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<E> extends LinkedHashSet<String> {
@Override
public String toString() {
// ...
}
}
UserHandler (where the exception occurs)
public ChatNotificationHashSet<String> getChatNotificationMessage() {
return (ChatNotificationHashSet<String>) pref.getStringSet(CHAT_NOTIFICATION_MESSAGE, null); // <- Exception occurs here
}
public void setChatNotificationMessage(ChatNotificationHashSet<String> messages) {
SharedPreferences.Editor editor = pref.edit();
editor.putStringSet(CHAT_NOTIFICATION_MESSAGE, messages);
editor.commit();
}
How can this happen? There shouldn't be any problems when casting null
to ChatNotificationHashSet<String>
, right? I couldn't think of any other problem.