2016-12-30 43 views
0

我建立DTO用于数据阵列(从JSON)对象并执行parcelable发送DTO的数组列表到另一个类,但我面对解组异常与自定义Parcelable对象

解组未知类型代码7471216 at offset 476 this issue

。我认为列表答案读/写parcelling有一些问题。我无法找到该错误。我正在发送我的数据列表,如intent.putParcelableArrayListExtra("xxxxx", MyList);,但在获取另一个活动时我收到了上述错误。请帮忙。

response{ 
"errorMessage": null, 
"status": true, 
"data": [ 
    { 
    "id": "xxxx", 
    "question": "Why is your xxxx?", 
    "isMandatory": true, 
    "typeOfQuestion": "OPEN", 
    "answers": [ 

    ], 
    "active": true 
}, 
{ 
    "id": "xxxxx", 
    "question": "what is your name", 
    "isMandatory": true, 
    "typeOfQuestion": "OPEN", 
    "answers": [ 

    ], 
    "active": true 
    } 
], 
"httpStatus": 200 
}  

Parcelable类:

​​
+0

请注明该活动获取数组列表的代码。 –

+0

@ sharma.mashesh,看着你的个人资料我注意到你几乎从不接受答案。如果他们帮助你解决你的问题,你应该接受更多的答案。如果你这样做,你可能会帮助有同样问题的其他人。 –

+0

肯定会做.. @ Rolfツ –

回答

3

你在写作和阅读是不正确的顺序。当使用Parcels序列化和反序列化对象时,您必须按照您写入对象的相同顺序读取您的必须

见更正后的代码如下(我感动的QuestionAnswerDto构造函数的最后一行):

@Override 
public void writeToParcel(Parcel dest, int flags) { 
    dest.writeString(this.id); 
    dest.writeString(this.question); 
    dest.writeString(this.typeOfQuestion); 
    dest.writeString(this.active); 
    dest.writeString(this.isMandatory); 
    dest.writeStringList(this.answers); 
} 


protected QuestionAnswerDto(Parcel in) { 
    this.id = in.readString(); 
    this.question = in.readString(); 
    this.typeOfQuestion = in.readString(); 
    this.active = in.readString(); 
    this.isMandatory = in.readString(); 
    this.answers = new ArrayList<>(); 
    in.readStringList(this.answers); 
}