NullPointerException: with ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference

来源:互联网 发布:java常考面试题 编辑:程序博客网 时间:2024/04/30 08:52

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);
                                             
0 0
原创粉丝点击