2016-12-05 137 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在这里被调用。