Getting Null Pointer Exception While Setting The Title To Action Bar
Error:Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setTitle(java.lang.CharSequence)' on a null object reference tried
Solution 1:
Some premisses:
- Check if you had declared
import android.support.v7.app.AppCompatActivity
and your activity is extended it. - Check if you declared WINDOWS_FEATURE:
requestWindowFeature(Window.FEATURE_ACTION_BAR);
or in your style:<item name="android:windowActionBar">true</item>
regards,
Solution 2:
Its the problem in the style sheet That says
"<style name="AppTheme.NoActionBar">"
Define some theme then you get rid of null pointer exception
Solution 3:
If you are using an INTENT with AppCompatActivity, you need to access to the same relevant thread:
YourClass mContext;
mContext.runOnUiThread(newRunnable() {
@Overridepublicvoidrun() {
mContext.getSupportActionBar().hide();
}
});
YourClass is the one extending AppCompActivity:
publicclassYourClassextendsAppCompatActivity {
}
Post a Comment for "Getting Null Pointer Exception While Setting The Title To Action Bar"