Class not found when Unmarshalling Android Intent Parcelable

前端 未结 2 1463
轮回少年
轮回少年 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();
        parcel.readArrayList(this.choices, Choices.Creator);
    }
    

提交回复
热议问题