2015-04-03 46 views
-2
04-03 10:19:34.572 2189-2189/com.techexpert4u.duaaadhkaar E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    Process: com.techexpert4u.duaaadhkaar, PID: 2189 
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.techexpert4u.duaaadhkaar/com.techexpert4u.duaaadhkaar.MainActivity}: java.lang.NullPointerException 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
      at android.app.ActivityThread.access$800(ActivityThread.java:135) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:136) 
      at android.app.ActivityThread.main(ActivityThread.java:5017) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
      at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.NullPointerException 
      at com.techexpert4u.duaaadhkaar.MainActivity.onPostCreate(MainActivity.java:936) 
      at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1150) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2178) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
      at android.app.ActivityThread.access$800(ActivityThread.java:135) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:136) 
      at android.app.ActivityThread.main(ActivityThread.java:5017) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
      at dalvik.system.NativeStart.main(Native Method) 

我需要幫助這個請幫助我。引起︰java.lang.NullPointerException MainActivity.onPostCreate

@Override 
protected void onPostCreate(Bundle savedInstanceState) { 
    super.onPostCreate(savedInstanceState); 
    // Sync the toggle state after onRestoreInstanceState has occurred. 
    mDrawerToggle.syncState(); 
} 

回答

0

鑑於源和棧跟蹤,顯然mDrawerTogglenull

+0

哪裏在代碼中我找不到它。 – Solaiman 2015-04-03 22:52:56

+1

@Solaiman如果你關注你的堆棧跟蹤,你會發現它在936行。你如何初始化你的'mDrawerToggle'對象? – joao2fast4u 2015-04-03 22:59:17

+0

我做到了,我仍然有問題。我在 – Solaiman 2015-04-03 23:59:22

0

null mDrawerToggle字段似乎應該在initializeDrawer()的代碼中初始化,但沒有證據表明您曾經調用該方法。

在onCreate()中調用initializeDrawer,或者確保它在之前的任何代碼路徑中發生,然後嘗試使用mDrawerToggle。

+0

以下發布了代碼抱歉,我沒有安靜的理解你,因爲我是編程方面的新手。你能多解釋一下嗎?提前致謝。你的意思是我需要把它放在onCreat() – Solaiman 2015-04-05 04:40:58

+0

你永遠不會調用initializeDrawer(),所以你永遠不會完成它打算做的初始化。在onCreate()中打一個電話確實是第一個想到的想法,但知道什麼是最好的需要更多地瞭解你的程序。 – 2015-04-05 06:02:16

+0

謝謝,我明白了。現在我有另一個問題。 – Solaiman 2015-04-05 07:37:08

相關問題