-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());
}