当前位置: 首页 > 知识库问答 >
问题:

Android:解组java.lang.ClassNotFoundException时未找到类

徐飞龙
2023-03-14

我的班级照片列表:

public class PhotosList extends DataList<Photo> {

public PhotosList() {}

@SuppressWarnings("unused")
public PhotosList(Parcel source) {
    super(source);
    items = new ArrayList<>();
    source.readList(items, Photo.class.getClassLoader());
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    super.writeToParcel(dest, flags);
    dest.writeList(items);
}

...

我的班级照片:

public class Photo extends BaseModel {

@SerializedName("photos")
public ArrayList<Image> images;

@SuppressWarnings("unused")
public Photo() {}

@SuppressWarnings("unused")
public Photo(Parcel source) {
    super(source);
    images = new ArrayList<>();
    source.readList(images, Image.class.getClassLoader());
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    super.writeToParcel(dest, flags);
    dest.writeList(images);
}

...
public class DataList<T> implements Parcelable {

@SerializedName("total_count")
public int total;

@SerializedName("message")
public String message;

@SerializedName("items")
public ArrayList<T> items;

@SuppressWarnings("unused")
public DataList() {}

@SuppressWarnings("unused")
public DataList(Parcel source) {
    total = source.readInt();
    message = source.readString();
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeInt(total);
    dest.writeString(message);
}
getIntent().setExtrasClassLoader(PhotosList.class.getClassLoader());
        PhotosList photosList = bundle.getParcelable(BUNDLE_KEY_PHOTOS);

共有1个答案

彭存
2023-03-14

您应该参考这篇文章,从“Parcelable,the Speed King”开始阅读。缺少DescripeContents()和内部类声明Parcelable.Creator Creator

 类似资料: