1

i want to work with action bar in android. for this i use

getActionBar().setHomeButtonEnabled(true);

below the SetContentView . but is gives me null pointer exception. when i try only getActionBar() it works fine.

please help me.

vivek tiwari
  • 645
  • 3
  • 10
  • 23

2 Answers2

9

If your activity does not have a title bar the method getActionBar() can return null.

You have two options to fix this:

1- Add getWindow().requestFeature(Window.FEATURE_ACTION_BAR); before setContentView

2- In your Manifest specify a Theme that supports ActionBar

Also make sure that you are targeting the right android version e.g. <uses-sdk android:minSdkVersion="11" />

iTech
  • 18,192
  • 4
  • 57
  • 80
0

getActionBar() will return null for pre Honeycomb devices.

If you are targeting Android v2.3 to 4.2 try out ActionBarSherlock.

Yaroslav Mytkalyk
  • 16,950
  • 10
  • 72
  • 99
Kiran Kumar
  • 1,192
  • 8
  • 10