Skip to content Skip to sidebar Skip to footer

Actionbar Giving Nullpointerexception?

I've been trying to figure this one out for a while. I have an app that uses the action bar but every time I want to call it in comes up null. Giving this error 12-01 10:54:11.

Solution 1:

if you are using the support library then you have to use getSupportActionBar() instead of getActionBar(), and instead of extends Activity you have to extends ActionBarActivity. Here you can find the documentation

Solution 2:

you declare your AppTheme with the actionbar hidden: WIth these flags, it will never be there

<!-- Application theme. --><stylename="AppTheme"parent="AppBaseTheme"><!-- All customizations that are NOT specific to a particular API-level can go here. --><itemname="android:windowNoTitle">true</item><!-- Hides the Action Bar --><itemname="android:windowFullscreen">true</item><!-- Hides the status bar --></style>

Solution 3:

Your getActionBar method is not returning anything i suppose, it is null, so it is unable to call the hide method.

By the way, how are you supposed to get ActionBar reference directly using getActionBar when you haven't even extended your Activity from ActionBarActivity???

Solution 4:

if you are using support library put the code in this way

public class Signup extends Activity 
{
  protected void onCreate(Bundle savedInstanceState) 
  {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.signup);
        getSupportActionBar().hide();
        SetListeners();
    }

....

Post a Comment for "Actionbar Giving Nullpointerexception?"