Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAVAParcel@e7a33b1:解组未知类型的arraylist_Java_Android_Arraylist_Parcelable_Parcel - Fatal编程技术网

JAVAParcel@e7a33b1:解组未知类型的arraylist

JAVAParcel@e7a33b1:解组未知类型的arraylist,java,android,arraylist,parcelable,parcel,Java,Android,Arraylist,Parcelable,Parcel,我试图使用Parcelable在android中传递数据,但我在这行中遇到了一个错误,因为我使用了正确的类型,我不知道我在这里错过了什么 以下是包裹中出现问题的对象: ArrayList<SecondChildCategory> secondChildCategories; public ArrayList<SecondChildCategory> getSecondChildCategories() { return secondChildCate

我试图使用
Parcelable
在android中传递数据,但我在这行中遇到了一个错误,因为我使用了正确的类型,我不知道我在这里错过了什么

以下是包裹中出现问题的对象:

ArrayList<SecondChildCategory> secondChildCategories;
   public ArrayList<SecondChildCategory> getSecondChildCategories() {
        return secondChildCategories;
    }

    public void setSecondChildCategories(ArrayList<SecondChildCategory> secondChildCategories) {
        this.secondChildCategories = secondChildCategories;
    }
我是这样写的:

@Override
public void writeToParcel(Parcel parcel, int i) {
    parcel.writeInt(id);
    parcel.writeString(image);
    parcel.writeString(softDelete);
    parcel.writeInt(productCategoryId);
    parcel.writeString(createdAt);
    parcel.writeString(updatedAt);
    parcel.writeString(parentCategoryID);
    parcel.writeString(backgroundColor);
    parcel.writeString(name);
    parcel.writeList(secondChildCategories);
    parcel.writeByte((byte) (hasChild ? 1 : 0));

}
我有一个错误:

原因:java.lang.RuntimeException:Parcel android.os。Parcel@e7a33b1:在偏移量372处解组未知类型代码7143535

在这一行代码中:

secondChildCategories = in.readArrayList(SecondChildCategory.class.getClassLoader());

您应该使用其他方法来写入和读取
包裹列表
s:

  • 用于写入
    包裹

    parcel.writeTypedList(第二儿童类别)

  • 用于读取
    包裹
    (也可以使用)

    secondChildCategories=in.createTypedArrayList(secondChildCategories.CREATOR)


  • 希望有帮助。

    您读取int的方式不正确。如果您有
    writeInt
    调用,那么您应该有相应的
    readInt
    调用,而没有其他调用(如果您先调用
    readByte
    ,然后数据位置移动,下一次调用
    readInt
    读取不正确的字节)。使用
    if(in.readByte()==0)
    条件,您希望实现什么?我得到了一个int值错误,并通过这种方式解决了它,因为我记得rbtw,我删除了这个if,您的答案很有效,非常感谢:)
    secondChildCategories = in.readArrayList(SecondChildCategory.class.getClassLoader());