getSupportActionBar() always returns null

1,959 views
Skip to first unread message

Christopher Perry

unread,
Sep 4, 2011, 1:57:47 AM9/4/11
to ActionBarSherlock
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/
com.actionbarsherlock.sample.demos.app.ActionBarTabNavigation}:
java.lang.NullPointerException 09-03 02:34:47.940: ERROR/
AndroidRuntime(3078): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
1748) 09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
1764) 09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at
android.app.ActivityThread.access$1500(ActivityThread.java:122) 09-03
02:34:47.940: ERROR/AndroidRuntime(3078): at android.app.ActivityThread
$H.handleMessage(ActivityThread.java:1002) 09-03 02:34:47.940: ERROR/
AndroidRuntime(3078): at
android.os.Handler.dispatchMessage(Handler.java:99) 09-03
02:34:47.940: ERROR/AndroidRuntime(3078): at
android.os.Looper.loop(Looper.java:132) 09-03 02:34:47.940: ERROR/
AndroidRuntime(3078): at
android.app.ActivityThread.main(ActivityThread.java:4025) 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(Method.java:491) 09-03 02:34:47.940:
ERROR/AndroidRuntime(3078): at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:841) 09-03 02:34:47.940:
ERROR/AndroidRuntime(3078): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 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
com.actionbarsherlock.sample.demos.app.ActionBarTabNavigation.onCreate(ActionBarTabNavigation.java:
19) 09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1048) 09-03 02:34:47.940: ERROR/AndroidRuntime(3078): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
1712) 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.

Jake Wharton

unread,
Sep 5, 2011, 3:41:17 PM9/5/11
to actionba...@googlegroups.com
A few questions:

What version of Android are you running the demo on?
Who makes the phone/tablet you are running it on?
Do the other demos with the action bar work?

---
Jake Wharton
http://about.me/jakewharton

Christopher Perry

unread,
Sep 5, 2011, 4:07:30 PM9/5/11
to actionba...@googlegroups.com
Hey Jake,

Sorry for wasting your time, I was using your Light theme on the Application tag in the manifest, but overlooked that my startup activity was using an Android  no title bar theme, which of course would cause the action bar to be null. I removed the theme from the activity and everything is fine now.

The sample app does still crash when trying to view tabbed navigation, but at least I've got my stuff working. Great job btw, very nice library. :)

Chris

Jake Wharton

unread,
Sep 5, 2011, 4:30:01 PM9/5/11
to actionba...@googlegroups.com
Not a problem at all. As this library is a bit more complex than your average drop-in component, there's a bit of a learning curve on getting it up and running properly. I keep meaning to update the website to provide more tutorial-based instructions for cases like this.

Christopher Perry

unread,
Sep 5, 2011, 6:29:45 PM9/5/11
to actionba...@googlegroups.com
I appreciate your time man, your library is a life saver. I'm using it to port my app "Moola" to tablet, and I wanted tab navigation with backwards compatibility and the action bar stuff. 

Stanislas Williamsko SOUZA

unread,
Mar 13, 2014, 5:16:27 PM3/13/14
to actionba...@googlegroups.com
Hey jack,

home you are fine.Im facing the problem on a samsung galaxy Android 4.1.2.
Can you help me to fix it  please? i have done many searchs but all the solutions provided are not working on this phone.

thank you for advance
Reply all
Reply to author
Forward
0 new messages