There are a number of questions dealing with this error. The solutions to these are:
- have the MainActivity class extend AppCompatActivity
- call getSupportActionBar(), not getActionBar()
I am already doing these.
I see a difference in appcompat-v7 22.1.1 and appcompat-v7 23.1.1. I get the error in 23. In 22 it works fine.
Stepping through the code in the debugger, I see that in AppCompatDelegateImplV7.intWindowDecorActionBar(),
mHasActionBar is false, causing mActionBar to not be instantiated.
Stepping through the code in 22.1.1, the code is slightly different, but ultimately, I see that mHasActionBar is true and so the code works.
How do I deal with this?
import android.support.v7.app.ActionBar;
...
public class MainActivity extends AppCompatActivity implements ...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.ic_drawer);
....
}