1
나는이 코드 조각의 끝에서 NullPointerException이 얻을 :이의 스크린 샷이다널 포인터 예외는 '마지막'블록
05-07 12:55:06.775: V/GCMBroadcastReceiver(19555): onReceive: com.google.android.c2dm.intent.RECEIVE
05-07 12:55:06.775: V/GCMBroadcastReceiver(19555): GCM IntentService class: com.predictoo.whimbee.GCMIntentService
05-07 12:55:06.775: V/GCMBaseIntentService(19555): Acquiring wakelock
05-07 12:55:06.815: D/GCMIntentService(19555): onMessage - context: android.app.Appli[email protected]
05-07 12:55:06.815: V/GCMBaseIntentService(19555): Releasing wakelock
:
@Override
public final void onHandleIntent(Intent intent) {
try {
Context context = getApplicationContext();
String action = intent.getAction();
if (action.equals(INTENT_FROM_GCM_REGISTRATION_CALLBACK)) {
handleRegistration(context, intent);
} else if (action.equals(INTENT_FROM_GCM_MESSAGE)) {
// checks for special messages
String messageType =
intent.getStringExtra(EXTRA_SPECIAL_MESSAGE);
if (messageType != null) {
if (messageType.equals(VALUE_DELETED_MESSAGES)) {
String sTotal =
intent.getStringExtra(EXTRA_TOTAL_DELETED);
if (sTotal != null) {
try {
int total = Integer.parseInt(sTotal);
Log.v(TAG, "Received deleted messages " +
"notification: " + total);
onDeletedMessages(context, total);
} catch (NumberFormatException e) {
Log.e(TAG, "GCM returned invalid number of " +
"deleted messages: " + sTotal);
}
}
} else {
// application is not using the latest GCM library
Log.e(TAG, "Received unknown special message: " +
messageType);
}
} else {
onMessage(context, intent);
}
} else if (action.equals(INTENT_FROM_GCM_LIBRARY_RETRY)) {
String token = intent.getStringExtra(EXTRA_TOKEN);
if (!TOKEN.equals(token)) {
// make sure intent was generated by this class, not by a
// malicious app.
Log.e(TAG, "Received invalid token: " + token);
return;
}
// retry last call
if (GCMRegistrar.isRegistered(context)) {
GCMRegistrar.internalUnregister(context);
} else {
GCMRegistrar.internalRegister(context, mSenderId);
}
}
} finally {
// Release the power lock, so phone can get back to sleep.
// The lock is reference-counted by default, so multiple
// messages are ok.
// If onMessage() needs to spawn a thread or do something else,
// it should use its own lock.
synchronized (LOCK) {
// sanity check for null as this is a public method
if (sWakeLock != null) {
Log.v(TAG, "Releasing wakelock");
if(sWakeLock.isHeld()){
sWakeLock.release();
}
} else {
// should never happen during normal workflow
Log.e(TAG, "Wakelock reference is null");
}
}
} // NullPointerException apparently thrown here
}
이것은 로그 캣입니다 오류 :
catch 블록을 추가 한 후, 나는 실제 일을 가지고 예외 추적 표 :
05-07 14:15:38.216: W/System.err(26532): java.lang.NullPointerException: println needs a message
05-07 14:15:38.226: W/System.err(26532): at android.util.Log.println_native(Native Method)
05-07 14:15:38.226: W/System.err(26532): at android.util.Log.v(Log.java:119)
05-07 14:15:38.226: W/System.err(26532): at com.predictoo.whimbee.GCMIntentService.onMessage(GCMIntentService.java:63)
05-07 14:15:38.226: W/System.err(26532): at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:179)
05-07 14:15:38.226: W/System.err(26532): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
05-07 14:15:38.236: W/System.err(26532): at android.os.Handler.dispatchMessage(Handler.java:99)
05-07 14:15:38.236: W/System.err(26532): at android.os.Looper.loop(Looper.java:137)
05-07 14:15:38.236: W/System.err(26532): at android.os.HandlerThread.run(HandlerThread.java:60)
예외는 어디에서 발생합니까? –
@VKSingla 예외를 던지는 줄에 인용 부호를 추가했습니다. 마지막 대괄호 앞에있는 마지막 줄 중 하나입니다. –
finally 블록 다음에 예외가 실제로 throw되지 않습니다. finally 블록은 try 블록 내부에 선언되지 않은 예외가 발생하더라도 항상 실행됩니다. 따라서 실제 예외는 try 블록 내부에서 발생하며 스택 추적의 행 번호로 식별 할 수 있습니다. – NilsH