java.lang.RuntimeException: Parcel android.os.Parcel: Unmarshalling unknown type code

前端 未结 2 1231
傲寒
傲寒 2021-01-08 01:07

I seem to be getting a strange error in my app (see GitHub), which occurs when I pass objects to different activities that implement Parcelable.

I have

2条回答
  •  醉梦人生
    2021-01-08 01:38

    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);
    }
    

提交回复
热议问题