2016-12-05 126 views
-1

我希望有人可以幫助我在這裏。我似乎無法追查是什麼原因造成的。我正在測試Firebase消息。 onMessageReceived成功命中,但是當我打電話NotificationManager.notify我得到這個錯誤:無法銷燬活動... java.lang.NullPointerException:observer

E/UncaughtException:了java.lang.RuntimeException:無法摧毀 活動{com.myproject.android/com.myproject.android .MainActivity}: 顯示java.lang.NullPointerException:觀察者

public class MyFirebaseMessagingService extends FirebaseMessagingService { 
     public void onMessageReceived(RemoteMessage remoteMessage) { 
       RemoteMessage.Notification notification = remoteMessage.getNotification(); 
       createNotification(notification); 
     } 
    } 



private void createNotification(RemoteMessage.Notification notification) { 
    Context context = getBaseContext(); 
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setContentText(notification.getBody()); 
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build()); 
} 

回答

0

我想我想通了。我的MainActivity onDestroy中有一些代碼不應該在那裏。這個錯誤讓我失望,因爲我不知道爲什麼我的MainActivity onDestroy在這裏被調用。