Getactionbar is null

We use getactionbar to get the actionbar instance, hide it or do other operations.

ActionBar actionBar = getActionBar();

But I did, but actionbar is null.

The problem is caused by the base class of activity. When using the base class of appcompatactivity or other support packages, you need to use another corresponding method to get the actionbar instance, that is, getsupportactionbar (), and the actionbar also needs to use the base class of the corresponding support package. actionBar = getSupportActionBar();

In this way, the null pointer will not be reported.

original text

Read More: