onOptionsItemSelected意外关闭抽屉

时间:2015-05-02 08:27:46

标签: android android-studio

我正在this guide之后创建一个导航抽屉。

当按下打开抽屉的图标时,我做了所有事情,但应用程序强制关闭。

当我删除它时:

if (mDrawerToggle.onOptionsItemSelected(item)) {
    return true;
}

位于onOptionsItemSelected()方法下,该应用不会强行关闭,但图标无法打开导航抽屉。

logcat的

05-02 08:23:30.560    2449-2449/com.mrad4tech.drawwer.mrad4techdr D/AndroidRuntime﹕ Shutting down VM 05-02 08:23:30.561    2449-2449/com.mrad4tech.drawwer.mrad4techdr E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.mrad4tech.drawwer.mrad4techdr, PID: 2449
    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.support.v7.app.ActionBarDrawerToggle.onOptionsItemSelected(android.view.MenuItem)' on a null object reference
            at com.mrad4tech.drawwer.mrad4techdr.webview.onOptionsItemSelected(webview.java:98)
            at android.app.Activity.onMenuItemSelected(Activity.java:2882)
            at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:353)
            at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:144)
            at android.support.v7.internal.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:99)
            at android.support.v7.internal.widget.ToolbarWidgetWrapper$1.onClick(ToolbarWidgetWrapper.java:190)
            at android.view.View.performClick(View.java:4756)
            at android.view.View$PerformClick.run(View.java:19749)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 05-02 08:23:30.567    1232-2242/system_process W/ActivityManager﹕ Force finishing activity com.mrad4tech.drawwer.mrad4techdr/.webview 05-02 08:23:30.579    1232-1280/system_process W/AudioTrack﹕ AUDIO_OUTPUT_FLAG_FAST denied by client 05-02 08:23:30.581    2449-2464/com.mrad4tech.drawwer.mrad4techdr E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000b44 05-02 08:23:30.622    2449-2464/com.mrad4tech.drawwer.mrad4techdr E/eglCodecCommon﹕ glUtilsParamSize: unknow param 0x00000bd0 05-02 08:23:30.689    1232-2199/system_process I/OpenGLRenderer﹕ Initialized EGL, version 1.4 
05-02 08:23:30.746    1232-2199/system_process W/EGL_emulation﹕ eglSurfaceAttrib not implemented 
05-02 08:23:30.746    1232-2199/system_process W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xb0a14820, error=EGL_SUCCESS 
05-02 08:23:30.791    2449-2464/com.mrad4tech.drawwer.mrad4techdr E/eglCodecCommon﹕ **** ERROR unknown type 0x73000d (glSizeof,72) 
05-02 08:23:31.777    1232-1250/system_process I/Choreographer﹕ Skipped 56 frames!  The application may be doing too much work on its main thread. 
05-02 08:23:31.814    1232-1250/system_process W/ActivityManager﹕ Activity pause timeout for ActivityRecord{1c9d519c u0 com.mrad4tech.drawwer.mrad4techdr/.webview t70 f} 
05-02 08:23:40.573    1232-1250/system_process W/ActivityManager﹕ Launch timeout has expired, giving up wake lock!

1 个答案:

答案 0 :(得分:0)

mDrawerToggle在您的活动中为空,可能在

之前未初始化