Class not found when Unmarshalling Android Intent Parcelable

前端 未结 2 1453
轮回少年
轮回少年 2020-12-17 10:39

I have a ArrayList that I am passing between activities. In this ArrayList are objects made from a class that has four va

相关标签:
2条回答
  • 2020-12-17 10:52

    You should set the ClassLoader. Try this:

    public Question (Parcel parcel) {
        this.id = parcel.readString();
        this.text = parcel.readString();
        this.image = parcel.readString();
        this.choices = parcel.readTypedList(Choices.class.getClassLoader());
    }
    

    Also you can try to read and write a typed List instead of an ArrayList:

    public Question (Parcel parcel) {
        this.id = parcel.readString();
        this.text = parcel.readString();
        this.image = parcel.readString();
        this.choices = new ArrayList<Choices>();
        parcel.readArrayList(this.choices, Choices.Creator);
    }
    
    0 讨论(0)
  • 2020-12-17 10:54

    You should try replacing this.choices = parcel.readArrayList(null); by this.choices = parcel.readArrayList(Choices.class.getClassLoader());

    Hope this helps

    0 讨论(0)
提交回复
热议问题