【发布时间】:2016-12-30 09:13:42
【问题描述】:
我正在为数据数组(来自 json)对象创建 DTO 并实现 parcelable 以将 DTO 的数组列表发送到另一个类,但我面临
在此问题的偏移量 476 处解组未知类型代码 7471216
。我认为 List answers read\write 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 类:
public class QuestionAnswerDto implements Parcelable {
private String id;
private String question;
private String isMandatory;
private String typeOfQuestion;
private String active;
private List<String> answers;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public String getIsMandatory() {
return isMandatory;
}
public void setIsMandatory(String isMandatory) {
this.isMandatory = isMandatory;
}
public String getTypeOfQuestion() {
return typeOfQuestion;
}
public void setTypeOfQuestion(String typeOfQuestion) {
this.typeOfQuestion = typeOfQuestion;
}
public String getActive() {
return active;
}
public void setActive(String active) {
this.active = active;
}
public List<String> getAnswers() {
return answers;
}
public void setAnswers(List<String> answers) {
this.answers = answers;
}
@Override
public int describeContents() {
return 0;
}
@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.answers = new ArrayList<>();
in.readStringList(this.answers);
this.isMandatory = in.readString();
}
public static final Creator<QuestionAnswerDto> CREATOR = new Creator<QuestionAnswerDto>() {
public QuestionAnswerDto createFromParcel(Parcel source) {
return new QuestionAnswerDto(source);
}
public QuestionAnswerDto[] newArray(int size) {
return new QuestionAnswerDto[size];
}
};
}
【问题讨论】:
-
请在活动中提及获取数组列表的代码。
-
@sharma.mashes,查看您的个人资料,我注意到您几乎从不接受答案。如果他们帮助您解决问题,您应该接受更多答案。如果你这样做,你可能会帮助其他有同样问题的人。
-
肯定会的 ..@Rolfツ
标签: android arraylist parcelable parcel