FATAL EXCEPTION: AsyncTask #2
Process: my.app, PID: 15441
java.lang.ClassCastException: java.util.HashSet cannot be cast to my.app.ChatNotificationHashSet
at my.app.UserHandler.getChatNotificationMessage(UserHandler.java:127)
at my.app.NotificationUtil.getChatTitle(NotificationUtil.java:100)
at my.app.NotificationUtil.showChat(NotificationUtil.java:71)
at my.app.service.GCMListenerService.onMessageReceived(GCMListenerService.java:47)
at com.google.android.gms.gcm.GcmListenerService.zzq(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService.zzp(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService.zzo(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService.zza(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService$1.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)ChatNotificationHashSet
public class ChatNotificationHashSet extends LinkedHashSet {
@Override
public String toString() {
// ...
}
}UserHandler(发生异常)
public ChatNotificationHashSet getChatNotificationMessage() {
return (ChatNotificationHashSet) pref.getStringSet(CHAT_NOTIFICATION_MESSAGE, null); //
}
public void setChatNotificationMessage(ChatNotificationHashSet messages) {
SharedPreferences.Editor editor = pref.edit();
editor.putStringSet(CHAT_NOTIFICATION_MESSAGE, messages);
editor.commit();
}
这怎么会发生?将null投射到ChatNotificationHashSet时应该没有任何问题,对吧?我想不出任何其他问题。