1

I am new to android. My minimum API level needs to be 7, so that I can test the app on my htc hero. My target API level is 17. The error concerns the actionbar. Some code is added by eclipse and I guess I need it to propperly run my app on the latest android versions:

getActionBar().setDisplayHomeAsUpEnabled(true);

getActionBar() gives NPE on API 7, but not on API 17. How do I solve this without deleting the code (which I will presumably need for modern API levels)?

sandrstar
  • 12,503
  • 8
  • 58
  • 65
hasdrubal
  • 1,024
  • 14
  • 30

3 Answers3

0

Basically, You need to follow this. If You need some good example, I think Android IO app source might be a good example on how to develop taking care about form-factor, API level etc. during runtime (however, it might be little bit difficult for completely new to android)

sandrstar
  • 12,503
  • 8
  • 58
  • 65
0

Action bar is not supported in any pre-honeycomb versions so any method related to action bar will not get executed....but after searching SO i came across this brilliant thing...

just check this out...

You can find out more information as well as screenshots of sample applications at link

The library is 100% open source and available at check this

from below question...

ActionBar pre Honeycomb

Community
  • 1
  • 1
karan
  • 8,637
  • 3
  • 41
  • 78
0

i think your device have android version 2.1 thats why you get error.

just add this actionbarsherlock lib to your Project.

after that just change this line

ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);

check this tutorials link and link

Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177