I’m trying to add the action bar programatically as shown in the dev documentaion but I’m coming across an error. My minSdk is set to 11, my application has one layout and one activity and the only code in the activity is:
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.inbox);
ActionBar actionBar = getActionBar();
actionBar.show();
}
If I take out those last two lines then my app runs. I know that the holo theme include the actionbar automatically, but I don’t like the editTextviews. Any ideas on why this is happening. Should I be using the HoloTheme and themeing the views differently?
Again, I’m not getting any errors in eclipse. My program is crashing from what I can decipher from logcat as an null pointer exception.
From the documentation you linked to:
Since you’re using a theme without an action bar,
getACtionBar()is returningnull, and then you’re attempting to callshow()on thatnull, resulting in an Exception being thrown.So that explains the error you’re getting. As far as what to do about it, the documentation for ActionBar says:
That gives you two easy options to have an ActionBar without using a Holo theme. This is probably simplest in your case:
Update: You should also switch to just
Theme.Blackwithout theNoTitleBarpart, as that prevents the ActionBar from working.