2014-02-28 65 views
1

中的消息。它將錯誤顯示爲空指針異常:println需要android中的消息e。我試圖將代碼從改變:在我的谷歌雲消息應用程序中,println需要android

Log.e("UnRegister Receiver Error", "> " + e.getMessage()); 

到:

String err = (e.getMessage()==null)?"UnRegister Receiver Error":e.getMessage(); 
Log.e("UnRegister Receiver Error", err); 

,但它仍然是相同的error.please幫助我。

@Override 
    protected void onDestroy() { 
     if (mRegisterTask != null) { 
      mRegisterTask.cancel(true); 

     } 
     try { 
      unregisterReceiver(mHandleMessageReceiver); 
      GCMRegistrar.onDestroy(this); 
     } catch (Exception e) { 

      //String err = (e.getMessage()==null)?"UnRegister Receiver Error":e.getMessage(); 
      //Log.e("UnRegister Receiver Error", err); 
      Log.e("UnRegister Receiver Error", "> " + e.getMessage()); 
     } 

     super.onDestroy(); 
    } 

的logcat:

02-28 22:58:35.254: E/AndroidRuntime(2812): FATAL EXCEPTION: IntentService[GCMIntentService-414538748674-1] 
02-28 22:58:35.254: E/AndroidRuntime(2812): java.lang.NullPointerException: println needs a message 
02-28 22:58:35.254: E/AndroidRuntime(2812):  at android.util.Log.println_native(Native Method) 
02-28 22:58:35.254: E/AndroidRuntime(2812):  at android.util.Log.d(Log.java:138) 
02-28 22:58:35.254: E/AndroidRuntime(2812):  at com.example.fitness2.GCMIntentService.onRegistered(GCMIntentService.java:29) 
02-28 22:58:35.254: E/AndroidRuntime(2812):  at com.google.android.gcm.GCMBaseIntentService.handleRegistration(GCMBaseIntentService.java:296) 
02-28 22:58:35.254: E/AndroidRuntime(2812):  at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:197) 
02-28 22:58:35.254: E/AndroidRuntime(2812):  at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65) 
02-28 22:58:35.254: E/AndroidRuntime(2812):  at android.os.Handler.dispatchMessage(Handler.java:99) 
02-28 22:58:35.254: E/AndroidRuntime(2812):  at android.os.Looper.loop(Looper.java:137) 
02-28 22:58:35.254: E/AndroidRuntime(2812):  at android.os.HandlerThread.run(HandlerThread.java:60) 
02-28 22:58:35.422: W/EGL_emulation(2812): eglSurfaceAttrib not implemented 
02-28 22:58:35.774: V/GCMRegistrar(2812): Unregistering receiver 
02-28 22:58:35.774: E/UnRegister Receiver Error(2812): Receiver not registered: [email protected] 
02-28 22:58:35.774: E/UnRegister Receiver Error(2812): > Receiver not registered: [email protected] 
+1

嗯,嗯,我沒有看到logcat日誌中的onDestroy ...你沒有提供代碼與日誌中的堆棧跟蹤 – Selvin

回答

1

您不必手動打印。你可以用它做printStackTrace如下

e.printStackTrace(); 

所有你需要做的就是這一行全部更換catch代碼。

您試圖註銷尚未註冊的廣播接收器的logcat天。 (請閱讀最後兩行)我想你已經忘記在開始時調用註冊接收器。

+1

El-Rahman El-Tama它仍然是相同的錯誤幫助PLZ – user3049804

+0

取代我的路線e,日誌行。如果你有相同的錯誤複製它給我 –

+0

相同的錯誤logcat我已經發布 – user3049804