Stack Overflow archive
0 score

Method Invocation actionbar.somemethod() may produce java null pointer exception

score
0
question views
1.4K
license
CC BY-SA 3.0

Your Activity (Moovo) inherits the application theme specified in your AndroidManifest. Your theme is a parent of Theme.AppCompat.Light.DarkActionBar. This theme removes the native android.app.ActionBar which is why getActionBar() returns null.

You should do one of two things:


First option:

Have your Activity class Moovo extend AppCompatActivity and use getSupportActionBar() instead of getActionBar().

Your changes would look something like this:

java
...

import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;

...

public class Moovo extends AppCompatActivity {

    ...

    @Override
    public void onCreate(Bundle savedInstanceState) {

        ...

        ActionBar actionBar = getSupportActionBar();

        ...

Second Option:

Do not use an AppCompat based theme. All AppCompat themes remove the native ActionBar and replace it with android.support.v7.app.ActionBar for backwards compatibility.

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.