我正在使用一个类通过Firebase消息发送我的通知,现在出现以下错误:
FATAL EXCEPTION: Firebase-NotifFirebaseMessagingService
Process: com.safshari.iwallpaper, PID: 3325
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
at com.safshari.iwallpaper.services.NotifFirebaseMessagingService.onMessageReceived(NotifFirebaseMessagingService.java:51)
at com.google.firebase.messaging.FirebaseMessagingService.zzd(Unknown Source)
at com.google.firebase.iid.zzc.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source)
at java.lang.Thread.run(Thread.java:762)
这是我用来发送或接收消息的firebasee消息传递类:
public class NotifFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FCM Service";
Bitmap bitmap;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String type = remoteMessage.getData().get("type");
String id = remoteMessage.getData().get("id");
String title = remoteMessage.getData().get("title");
String image = remoteMessage.getData().get("image");
String icon = remoteMessage.getData().get("icon");
String message = remoteMessage.getData().get("message");
PrefManager prf = new PrefManager(getApplicationContext());
if (!prf.getString("notifications").equals("false")) {
switch (type) {
case "wallpaper":
String wallpaper_title = remoteMessage.getData().get("wallpaper_title");
String wallpaper_size = remoteMessage.getData().get("wallpaper_size");
String wallpaper_sets = remoteMessage.getData().get("wallpaper_sets");
String wallpaper_review = remoteMessage.getData().get("wallpaper_review");
String wallpaper_downloads = remoteMessage.getData().get("wallpaper_downloads");
String wallpaper_resolution = remoteMessage.getData().get("wallpaper_resolution");
String wallpaper_color = remoteMessage.getData().get("wallpaper_color");
String wallpaper_user = remoteMessage.getData().get("wallpaper_user");
String wallpaper_comment = remoteMessage.getData().get("wallpaper_comment");
String wallpaper_type = remoteMessage.getData().get("wallpaper_type");
String wallpaper_description = remoteMessage.getData().get("wallpaper_description");
String wallpaper_extension = remoteMessage.getData().get("wallpaper_extension");
String wallpaper_thumbnail = remoteMessage.getData().get("wallpaper_thumbnail");
String wallpaper_image = remoteMessage.getData().get("wallpaper_image");
String wallpaper_wallpaper = remoteMessage.getData().get("wallpaper_wallpaper");
String wallpaper_userimage = remoteMessage.getData().get("wallpaper_userimage");
String wallpaper_created = remoteMessage.getData().get("wallpaper_created");
String wallpaper_comments = remoteMessage.getData().get("wallpaper_created");
sendNotification(
id,
title,
image,
icon,
message,
wallpaper_title,
wallpaper_size,
wallpaper_sets,
wallpaper_review,
wallpaper_downloads,
wallpaper_resolution,
wallpaper_color,
wallpaper_user,
wallpaper_comment,
wallpaper_type,
wallpaper_extension,
wallpaper_thumbnail,
wallpaper_image,
wallpaper_wallpaper,
wallpaper_userimage,
wallpaper_created,
wallpaper_comments,
wallpaper_description
);
break;
case "category":
String category_title = remoteMessage.getData().get("title_category");
String category_image = remoteMessage.getData().get("image_category");
sendNotificationCategory(
id,
title,
image,
icon,
message,
category_title,
category_image);
break;
case "link":
String link = remoteMessage.getData().get("link");
sendNotificationUrl(
id,
title,
image,
icon,
message,
link
);
break;
}
}
}
实际上,它是我的Firebase消息传递类的一部分,整个类都在300行以上,在运行第51行之前发生错误,在此之前我曾经使用过if而不是switch case,但是我设法使用了switch case但我不认为相关。