Android中捆绑包的错误幻数
我使用以下代码将数据从一个活动传递到另一个活动:
@Override
public void execute(List<Report> reports, Questions question) {
Intent replyIntent = new Intent(listener, ReplyActivity.class);
replyIntent.putExtra("id", 0L);
replyIntent.putExtra("questions", question);
listener.openReportOk(question);
listener.startActivity(replyIntent);
}
侦听器 它是回调的活动引用。
问题是这门课:
@Table(name = "Questions")
public class Questions extends Entity implements Parcelable {
public static final Creator<Questions> CREATOR = new Creator<Questions>() {
public Questions createFromParcel(Parcel source) {
return new Questions(source);
}
public Questions[] newArray(int size) {
return new Questions[size];
}
};
@TableField(name = "idReport", datatype = DATATYPE_INTEGER)
private int idReport;
@TableField(name = "nameReport", datatype = DATATYPE_STRING)
private String nameReport;
@TableField(name = "replyGroups", datatype = DATATYPE_STRING)
private String replyGroups;
@TableField(name = "questionGroups", datatype = DATATYPE_ENTITY)
private List<QuestionsGroup> questionsGroup;
private Boolean canCreateNew;
public Questions(int idReport, String nameReport, String replyGroups, List<QuestionsGroup> questionsGroup) {
this.idReport = idReport;
this.nameReport = nameReport;
this.replyGroups = replyGroups;
this.questionsGroup = questionsGroup;
this.canCreateNew = false;
}
public Questions() {
questionsGroup = new ArrayList<QuestionsGroup>();
}
private Questions(Parcel in) {
this();
this.idReport = in.readInt();
this.nameReport = in.readString();
this.replyGroups = in.readString();
Bundle b = in.readBundle(QuestionsGroup.class.getClassLoader());
this.questionsGroup = b.getParcelableArrayList("questionGroups");
this.canCreateNew = (Boolean) in.readValue(Boolean.class.getClassLoader());
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.idReport);
dest.writeString(this.nameReport);
dest.writeString(this.replyGroups);
Bundle b = new Bundle();
b.putParcelableArrayList("questionGroups", (ArrayList<QuestionsGroup>) this.questionsGroup);
dest.writeBundle(b);
dest.writeValue(this.canCreateNew);
}
}
当我在 onCreate 方法中接收包裹时:
private void getData(Intent data) {
ID = data.getExtras().getLong("id");
questions = data.getExtras().getParcelable("questions");
}
我收到此错误:
10-05 13:19:15.508 3499-3499/com.firext.android E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.firext.android, PID: 3499
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.firext.android/com.firext.android.activities.reply.ReplyActivity}: java.lang.IllegalStateException: Bad magic number for Bundle: 0x28
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2255)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.access$800(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1258)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5070)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)
Caused by: java.lang.IllegalStateException: Bad magic number for Bundle: 0x28
at android.os.BaseBundle.readFromParcelInner(BaseBundle.java:1342)
at android.os.BaseBundle.<init>(BaseBundle.java:90)
at android.os.Bundle.<init>(Bundle.java:66)
at android.os.Parcel.readBundle(Parcel.java:1645)
at com.firext.android.domain.QuestionsGroup.<init>(QuestionsGroup.java:53)
at com.firext.android.domain.QuestionsGroup$1.createFromParcel(QuestionsGroup.java:25)
at com.firext.android.domain.QuestionsGroup$1.createFromParcel(QuestionsGroup.java:23)
at android.os.Parcel.readParcelable(Parcel.java:2160)
at android.os.Parcel.readValue(Parcel.java:2066)
at android.os.Parcel.readListInternal(Parcel.java:2422)
at android.os.Parcel.readArrayList(Parcel.java:1756)
at android.os.Parcel.readValue(Parcel.java:2087)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2393)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getParcelableArrayList(Bundle.java:782)
at com.firext.android.domain.Questions.<init>(Questions.java:58)
at com.firext.android.domain.Questions.<init>(Questions.java:18)
at com.firext.android.domain.Questions$1.createFromParcel(Questions.java:22)
at com.firext.android.domain.Questions$1.createFromParcel(Questions.java:20)
at android.os.Parcel.readParcelable(Parcel.java:2160)
at android.os.Parcel.readValue(Parcel.java:2066)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2393)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getParcelable(Bundle.java:738)
at com.firext.android.activities.reply.ReplyActivity.getData(ReplyActivity.java:72)
at com.firext.android.activities.reply.ReplyActivity.onCreate(ReplyActivity.java:38)
at android.app.Activity.performCreate(Activity.java:5720)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1102)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2208)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.access$800(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1258)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5070)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)
怎么了?