小编Abi*_*bi-的帖子

ActionBarActivity getSupportActionBar().hide()抛出NullPointerException

呼叫

 if (getSupportActionBar() != null)
     getSupportActionBar().hide();
Run Code Online (Sandbox Code Playgroud)

要不就:

getActionBar()
Run Code Online (Sandbox Code Playgroud)

在android.support.v7.app.ActionBarActivity中,我得到了这样的异常:

    ...
    java.lang.NullPointerException
    at android.support.v7.app.ActionBarImplICS.hide(ActionBarImplICS.java:302)
    at android.support.v7.app.ActionBarImplJB.hide(ActionBarImplJB.java:20)
    ...
Run Code Online (Sandbox Code Playgroud)

编辑: 它只是在活动有主题时发生:

<style name="MyTheme" parent="Theme.AppCompat.Light">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">false</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

注意:

getSupportActionBar()
Run Code Online (Sandbox Code Playgroud)

不要返回null

java android nullpointerexception android-support-library android-actionbar-compat

4
推荐指数
2
解决办法
9893
查看次数