I'm having a problem saving/loading an ArrayList<HashMap<String, Object>>
across Android versions. I've been searching for the solution on Google and SO for days and everything I've tried didn't work.
This is the error I'm getting:
java.io.InvalidClassException: org.apache.harmony.luni.internal.util.ZoneInfo; Incompatible class (SUID): org.apache.harmony.luni.internal.util.ZoneInfo: static final long serialVersionUID =-8334108180457627365L; but expected org.apache.harmony.luni.internal.util.ZoneInfo: static final long serialVersionUID =2415005675580187790L;
I've tried implement Serializable
and static final long serialVersionUID = 1L
in the class containing ObjectInputStream and ObjectOutputStream but the error doesn开发者_开发问答't change. Further testing shows that the error doesn't even change on two different apps experiencing the same issue and the SUID's in the error depend entirely on the Android versions that the file was saved or trying to load in.
I've also tried Parcelable with no success.
How can I save and load the ArrayList without this issue?
Here are the SUID's for the ROM's I've tried:
G1 1.6 (CSDI V4 por Super@tmel): -1970599206206877388L Droid 2.2 (CyanogenMod 6.1.2): -8334108180457627365L Droid 2.3 (CyanogenMod 7 nightly 12): 2415005675580187790LYou have java.util.Calendar
or java.util.Timezone
in your map as value, don't you? Replace it with any other format should be OK, for example:
Calendar.getTimeInMillis()
or
Timezone.getRawOffset()
For some reasons, Dalvik changes serializationId on 'ZoneInfo' class.
I've concluded, awhile back actually (May/June), that the only way around this is to save the data in a database, which is the ideal way to go anyway.
I found databases to be a bit daunting to learn at first, but they're great once you understand how to use them. I highly recommend it for anyone who wants to store data, at least in a majority of cases. Here's the video that got me started with databases: http://youtube.com/watch?v=v61A90qlK9s
精彩评论