Parcelable Protocol Requires A Parcelable.creator Object Called Creator (i Do Have Creator)
Solution 1:
You are have different sequence when reading from Parcel than the one you write in.
In writeToParcel()
you are first putting String but in the HeatFriendDetail(Parcel in)
, you first read integer. It is not the correct way because the order or read/write matters.
Following is the code which makes correct order when writing/reading the data to/from Parcel (also see this link):
publicclassFriendDetailimplementsParcelable {
private String full_name;
privateint privacy;
publicHeatFriendDetail(Parcel in) {
this.full_name = in.readString();
this.privacy = in.readInt();
}
publicHeatFriendDetail() {
}
@OverridepublicvoidwriteToParcel(Parcel dest, int flags) {
dest.writeString(this.full_name);
dest.writeInt(this.privacy);
}
publicstaticfinal Parcelable.CreatorCREATOR=newParcelable.Creator() {
public HeatFriendDetail createFromParcel(Parcel in) {
returnnewHeatFriendDetail(in);
}
public HeatFriendDetail[] newArray(int size) {
returnnewHeatFriendDetail[size];
}
};
// GETTER SETTER//
}
Solution 2:
I received this error in release apk only, because the CREATOR was not public.
I changed this :
staticfinalParcelable.Creator<Station> CREATOR= new Parcelable.Creator<Station>() {
To this :
publicstaticfinalParcelable.Creator<Station> CREATOR= new Parcelable.Creator<Station>() {
Solution 3:
Just ran into this.
I had a hunch, and I looked in my ProGuard mapping file.
Normally I declare CREATOR like this:
publicstaticfinalParcelable.Creator<ClassA> CREATOR=
new Parcelable.Creator<ClassA>() {
which shows up in the mapping file like this:
android.os.Parcelable$Creator CREATOR -> CREATOR
..except for one class, the class that was reported with the error. I declared it like this:
publicstaticCreator<ClassB> CREATOR=
new Creator<ClassB>() {
Lo and behold:
android.os.Parcelable$Creator CREATOR -> a
So if you are getting this exception in your production release, check your mapping file. I think ProGuard is really sensitive to how CREATOR is declared when deciding not to obfuscate it.
Solution 4:
I had this error message when the CREATOR class was not static
Solution 5:
If you are using proguard rules add this line in to your proguard-rules.pro
-keepnames class * implementsandroid.os.Parcelable{
publicstaticfinal ** CREATOR;
}
Post a Comment for "Parcelable Protocol Requires A Parcelable.creator Object Called Creator (i Do Have Creator)"