NullPointerException: with ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
The cause of your issue is using MainActivity extend Activity
with support theme style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"
. It's incompatible things.
Which min sdk you need?
In your code having MainActivity extends Activity
you don't need AppCompatTheme
. Use name="AppTheme" parent="android:Theme.Light
"
If you are using Theme.AppCompat.Light.DarkActionBar
, you should extend your Activity
from AppCompatActivity
, and use getSupportActionBar()
.
Instead of:
public class MainActivity extends Activity {
use:
public class MainActivity extends AppCompatActivity {
and instead of:
getActionBar().setTitle(mTitles);
use:
getSupportActionBar().setTitle(mTitles);
This problem might be caused by your theme. Check it again, and make sure that it parent with Theme.AppCompat.Light.DarkActionBar
.
<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">true</item>
...
</style>
If your activity extends AppCompatActivity
or ActionBarActivity
, call getSupportActionBar()
.