3

I've implemented a class that implements Serializable object.

public class SaveMe implements Serializable {
    private static final long serialVersionUID = 1L;
    private String someValue1;
    private String someValue2;
} 

But whenever I try to use it in a Bundle, I get this exception:

 Parcelable encounteredClassNotFoundException reading a Serializable object
     at android.os.Parcel.readSerializable(Parcel.java:1951)
     at android.os.Parcel.readValue(Parcel.java:1822)
     at android.os.Parcel.readMapInternal(Parcel.java:2008)
     at android.os.Bundle.unparcel(Bundle.java:208)
     at android.os.Bundle.getString(Bundle.java:1034)

What am I doing wrong?

Edit

Hm... Similar issue when using Parcelable:

Class not found when unmarshalling
Vanuan
  • 31,770
  • 10
  • 98
  • 102
  • Can you show the method call that causes the exception? I've had issues with serializable as well... – Damp Feb 01 '11 at 20:39
  • 1
    actually, it is b.putSerializable("savedinstance", new SaveMe()) where b is a Bundle object. Then it is called implicitly when bundle gets restored. Actually, it is restored from another application. Maybe this is an issue? – Vanuan Feb 01 '11 at 20:52
  • 1
    If your other app doesn't know the class SaveMe that would probably be the case. – Damp Feb 01 '11 at 21:01

1 Answers1

0

I believe you may be running into class loader issues. You need to call setClassLoader() on the Bundle before you read serialized objects out of them.

Make sure you call setClassLoader(SaveMe.class.getClassLoader()) before reading from the bundle.

If the compiler cannot find SaveMe when compiling then for sure that class is missing in the target application as Damp suggested.

See this answer for more details: Parcelable inside bundle which is added to Parcel

Community
  • 1
  • 1
Nick Palmer
  • 2,589
  • 1
  • 25
  • 34