Proguard causing RuntimeException (Unmarshalling unknown type code) in Parcelable class
As we found out in the comments, the exception was the result of ProGuard obfuscating Parcelable classes. The fix is to include this snippet in the ProGuard configuration file:
-keepclassmembers class * implements android.os.Parcelable {
static ** CREATOR;
}
I guess the specific problem here was that ProGuard obfuscated the CREATOR
member of PagerSlidingTabStrip
, but since SavedState
is a subclass of View.BaseSavedState
, the superclass member was still available (this is why it didn't throw a BadParcelableException
), but that uses a different data structure and didn't write the custom attributes into the Parcel
output.
There is a recommended configuration for Android applications available in the ProGuard Manual, with detailed explanation about entries. For example, it includes that you should keep all class names used in the manifest or other XML files.
Android Parcelable: RuntimeException: Unmarshalling unknown type code
I would guess that this is happening when endDate == null
in your Occurrence
object. In this case, you're not writing a value to the Parcel, but the readFromParcel()
method is still trying to read it.
Maybe something like the following will help:
private void readFromParcel(Parcel in)
{
id = in.readInt();
startDate = new Date(in.readLong());
long date = in.readLong();
if (date != 0L)
{
endDate = new Date(date);
}
}
public void writeToParcel(Parcel dest, int flags)
{
dest.writeInt(id);
dest.writeLong(startDate.getTime());
if (endDate != null)
{
dest.writeLong(endDate.getTime());
}
else
{
dest.writeLong(0L);
}
}
How to fix Unmarshalling unknown type code XXX at offset YYY in Android?
It's because of Proguard obfuscation - it processed Parcelable.
solution: Proguard causing RuntimeException (Unmarshalling unknown type code) in Parcelable class
java.lang.RuntimeException: Parcel android.os.Parcel: Unmarshalling unknown type code
Your problem is in LanguagesFlashCard
. Here are your parcel/unparcel methods:
protected LanguagesFlashCard(Parcel in) {
mId = in.readInt();
mEnglish = in.readString();
mAnswerPrefix = in.readString();
mAnswer = in.readString();
mTier = in.readInt();
mTopic = in.readParcelable(Topic.class.getClassLoader());
}
As you can see, they don't match. The second item you write to the Parcel
is an int
, the second item you read from the Parcel
is a String
.
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mId);
dest.writeInt(mTier);
dest.writeString(mEnglish);
dest.writeString(mAnswerPrefix);
dest.writeString(mAnswer);
dest.writeParcelable(mTopic, flags);
}
Related Topics
Sniffing/Logging Your Own Android Bluetooth Traffic
Get List of Photo Galleries on Android
Custom Row in a Listpreference
Android - How to Pass Hashmap<String,String> Between Activities
How to Downgrade Android Emulator
Full Screen Dialogfragment in Android
Using Resultreceiver in Android
Programmatically Relaunch/Recreate an Activity
How to Keep My Android Service Running When the Screen Is Turned Off
Using Jaxb with Google Android
Sliding Drawer Appear in All Activities
Setonitemclicklistener on Custom Listview
Read & Writing Arrays of Parcelable Objects
How to Use Onsaveinstancestate() and Onrestoreinstancestate()