Android: getSupportActionBar() always returns null in ActionBarSherlock library

AndroidAndroid ActionbarActionbarsherlock

Android Problem Overview

I'm trying to use the ActionBarSherlock library to provide backwards compatible ActionBar support with tabs in my Android app, so I downloaded the latest build, built the demo, and ran it.

If you go to Action Bar, then select Tab Navigation it crashes every time. Here's the stack trace:

09-03 02:34:47.940: ERROR/AndroidRuntime(3078): FATAL EXCEPTION: main  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.actionbarsherlock.sample.demos/}: java.lang.NullPointerException  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at$1500(  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at$H.handleMessage(  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at android.os.Handler.dispatchMessage(  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at android.os.Looper.loop(  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at java.lang.reflect.Method.invokeNative(Native Method)  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at java.lang.reflect.Method.invoke(  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at$  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at dalvik.system.NativeStart.main(Native Method)  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): Caused by: java.lang.NullPointerException  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at  
09-03 02:34:47.940: ERROR/AndroidRuntime(3078): ... 11 more  

I can't move forward with my app until this is fixed. I wrote a bunch of code, set up the action bar in my app, and tried to run it, and it crashes with an NPE because of the null return value on the getSupportActionBar() call.

The relevant code is actually in the demo for the library:

public class ActionBarTabNavigation extends FragmentActivity implements ActionBar.TabListener {
	public void onCreate(Bundle savedInstanceState) {

			.add(, FragmentStackSupport.CountingFragment.newInstance(0))
		for (int i = 0; i < 3; i++) {
			ActionBar.Tab tab = getSupportActionBar().newTab();
			tab.setText("Tab " + i);

	public void onTabReselected(Tab tab, FragmentTransaction ft) {

	public void onTabSelected(Tab tab, FragmentTransaction ft) {
			.replace(, FragmentStackSupport.CountingFragment.newInstance(tab.getPosition()))

	public void onTabUnselected(Tab tab, FragmentTransaction ft) {

Android Solutions

Solution 1 - Android

You should add the Sherlock theme to your application

<application android:icon="@drawable/icon" android:label="@string/app_name"
		android:debuggable="false" android:theme="@style/Theme.Sherlock">

Solution 2 - Android

I had the same problem on the Android ICS 4.0.4. I was using requestWindowFeature(Window.FEATURE_NO_TITLE); on the FragmentActivity, but this was hiding the ActionBar on ICS+ devices that caused the getSupportActionBar() to be null.

Simply removed the:

And it worked like a charm.

Hope it helps someone.

Solution 3 - Android

Another reason this will happen on Honeycomb+ devices is because the windowNoTitle attribute is set in your style. Get rid of that as ActionBarSherlock will automatically remove it in pre-Honeycomb devices for you.

Solution 4 - Android

Another reason you might get null from getSupportActionBar() is trying to call it before setContentView(R.layout.main) or in your example adding a fragment.

I refactored oncreate and mistakenly put getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); after super.onCreate(savedInstanceState);

Solution 5 - Android

Heres a funny one: don't set the theme to -


Solution 6 - Android

Another reason you might get null from getSupportActionBar() is when the activity is used in a TabHost on Honeycomb+.

Solution 7 - Android

Depending how your write out code. ensure that you did set the toolbar first before calling it.

  mToolbar = (Toolbar) findViewById(;

Solution 8 - Android

I just changed in Manifest




and the error gone

Solution 9 - Android

whenever we set customview using sherlock library. just remove this requestWindowFeature(Window.FEATURE_NO_TITLE); like this we make customview using sherlock bar library..

	header_tvleft = (TextView) findViewById(;

Solution 10 - Android

I had this problem after (sillily) forgetting to call the super.onCreate()

Solution 11 - Android

you are declared Theme.Sherlock or Theme.Sherlock.Light as your activity or application theme in the manifest Or using a custom theme that inherits from one of these two


android:theme="@style/Theme.Sherlock.Light" >

also u can use dark theme:-


Solution 12 - Android

I added android:theme="@android:style/Theme.Dialog" to my activity in the Android Manifest file in an attempt to make it a dialogue activity. This too will remove the action bar hence a null pointer. Remove it or don't call getSupportActioBar

Solution 13 - Android

I ran into this after adding a library to my project. The remedy was to look in the library and remove any styles name "AppTheme" if you are using this same theme name in your manifest. There wasn't a conflict on my Galaxy S4, Jelly Bean, while there was a conflict on my Galaxy Tab.

Solution 14 - Android

I make this mistake because i add the toobar in the fragment xml file. The code to find the toolbar in fragment is this:getActivity().findViewByid(id...),but my toolbar is in fragment xml file,so that there was no toolbar found and no toolbar beeing setSipprotActionBar() and also nothing get when getSupportActionBar(). So remember :Do not put the toolbar in your fragment`s xml file.


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChristopher PerryView Question on Stackoverflow
Solution 1 - AndroidweakwireView Answer on Stackoverflow
Solution 2 - AndroidMario SantosView Answer on Stackoverflow
Solution 3 - AndroidDonn FelkerView Answer on Stackoverflow
Solution 4 - AndroidscottyabView Answer on Stackoverflow
Solution 5 - AndroidJY2kView Answer on Stackoverflow
Solution 6 - AndroidalebView Answer on Stackoverflow
Solution 7 - AndroidAlia Ramli RamliView Answer on Stackoverflow
Solution 8 - AndroidCodeToLifeView Answer on Stackoverflow
Solution 9 - AndroidharikrishnanView Answer on Stackoverflow
Solution 10 - AndroidNavarrView Answer on Stackoverflow
Solution 11 - AndroidDhavalView Answer on Stackoverflow
Solution 12 - Androidmugume davidView Answer on Stackoverflow
Solution 13 - AndroidChris SpragueView Answer on Stackoverflow
Solution 14 - AndroidnikerxuView Answer on Stackoverflow