从Fragment将ArrayList传递给Activity时抛出错误。我从来没有遇到过这种错误。只有当我将ArrayList传递给Activity时才会抛出错误。我已经搜索但是我没有得到解决问题的答案。你能检查一下我的代码并告诉我是否有任何错误。
java.lang.RuntimeException:Parcel android.os.Parcel@c154e0a: 在偏移884处解组未知类型代码101 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 在android.app.ActivityThread.-wrap14(ActivityThread.java) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1631) 在android.os.Handler.dispatchMessage(Handler.java:102) 在android.os.Looper.loop(Looper.java:154) 在android.app.ActivityThread.main(ActivityThread.java:6682) at java.lang.reflect.Method.invoke(Native Method) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1520) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 引起:java.lang.RuntimeException:Parcel android.os.Parcel@c154e0a:解组未知类型代码101 at 抵消884 在android.os.Parcel.readValue(Parcel.java:2453) 在android.os.Parcel.readArrayMapInternal(Parcel.java:2727) 在android.os.BaseBundle.unparcel(BaseBundle.java:269) 在android.os.BaseBundle.getSerializable(BaseBundle.java:1064) 在android.os.Bundle.getSerializable(Bundle.java:934) 在com.iroid.uiic.ui.main.vehiclelist.vehicle_detail_view.VehicleDetailViewActivity.onCreate(VehicleDetailViewActivity.java:39) 在android.app.Activity.performCreate(Activity.java:6942) 在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988) 在android.app.ActivityThread.-wrap14(ActivityThread.java) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1631) 在android.os.Handler.dispatchMessage(Handler.java:102) 在android.os.Looper.loop(Looper.java:154) 在android.app.ActivityThread.main(ActivityThread.java:6682) at java.lang.reflect.Method.invoke(Native Method) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1520) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
我的片段代码:
Intent intent = new Intent(getActivity(), VehicleDetailViewActivity.class);
Bundle args = new Bundle();
args.putParcelableArrayList("arrayList", arrayVehicleList);
args.putString("title",arrayVehicleList.get(position).getRegno());
args.putString("position", String.valueOf(position));
intent.putExtra("BUNDLE",args);
startActivity(intent);
我的活动代码:
Intent intent = getIntent();
Bundle args = intent.getBundleExtra("BUNDLE");
arrayVehicleList = (ArrayList<ModelVehicleList>)
args.getSerializable("arrayList");
title = (String) args.getSerializable("title");
position = (String) args.getSerializable("position");
我的模特课程:
public class ModelVehicleList implements Parcelable {
@SerializedName("user_id")
private String user_id;
@SerializedName("engine")
private String engine;
@SerializedName("odometerreading")
private String odometerreading;
@SerializedName("vehiclecolor")
private String vehiclecolor;
@SerializedName("regno")
private String regno;
@SerializedName("previousinsuranceNo")
private String previousinsuranceNo;
@SerializedName("previouspolicy")
private String previouspolicy;
@SerializedName("previousNCB")
private String previousNCB;
@SerializedName("frondimage")
private String frondimage;
@SerializedName("rearimage")
private String rearimage;
@SerializedName("leftimage")
private String leftimage;
@SerializedName("rightimage")
private String rightimage;
@SerializedName("speedometerimage")
private String speedometerimage;
@SerializedName("topimage")
private String topimage;
@SerializedName("status")
private String status;
@SerializedName("date")
private String date;
@SerializedName("time")
private String time;
@SerializedName("remarks")
private String remarks;
public static final Creator<ModelVehicleList> CREATOR = new Creator<ModelVehicleList>() {
@Override
public ModelVehicleList createFromParcel(Parcel in) {
return new ModelVehicleList(in);
}
@Override
public ModelVehicleList[] newArray(int size) {
return new ModelVehicleList[size];
}
};
public ModelVehicleList(Parcel in) {
user_id = in.readString();
status = in.readString();
date = in.readString();
time = in.readString();
// remarks = in.readString();
engine = in.readString();
odometerreading = in.readString();
vehiclecolor = in.readString();
regno = in.readString();
previousinsuranceNo = in.readString();
previouspolicy = in.readString();
previousNCB = in.readString();
frondimage = in.readString();
rearimage = in.readString();
speedometerimage = in.readString();
leftimage = in.readString();
rightimage = in.readString();
topimage = in.readString();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(status);
parcel.writeString(date);
parcel.writeString(time);
parcel.writeString(remarks);
parcel.writeString(user_id);
parcel.writeString(engine);
parcel.writeString(odometerreading);
parcel.writeString(vehiclecolor);
parcel.writeString(regno);
parcel.writeString(previousinsuranceNo);
parcel.writeString(previouspolicy);
parcel.writeString(previousNCB);
parcel.writeString(frondimage);
parcel.writeString(rearimage);
parcel.writeString(speedometerimage);
parcel.writeString(leftimage);
parcel.writeString(rightimage);
parcel.writeString(topimage);
}
public String getUser_id() {
return user_id;
}
public String getEngine() {
return engine;
}
public String getOdometerreading() {
return odometerreading;
}
public String getVehiclecolor() {
return vehiclecolor;
}
public String getRegno() {
return regno;
}
public String getPreviousinsuranceNo() {
return previousinsuranceNo;
}
public String getPreviouspolicy() {
return previouspolicy;
}
public String getPreviousNCB() {
return previousNCB;
}
public String getFrondimage() {
return frondimage;
}
public String getRearimage() {
return rearimage;
}
public String getLeftimage() {
return leftimage;
}
public String getRightimage() {
return rightimage;
}
public String getSpeedometerimage() {
return speedometerimage;
}
public String getTopimage() {
return topimage;
}
public String getStatus() {
return status;
}
public String getDate() {
return date;
}
public String getTime() {
return time;
}
public String getRemarks() {
return remarks;
}
}
答案 0 :(得分:0)
试试这个
Intent intent = new Intent(getActivity(), VehicleDetailViewActivity.class);
Bundle args = new Bundle();
args.putParcelableArrayList("arrayList", arrayVehicleList);
args.putString("title",arrayVehicleList.get(position).getRegno());
args.putString("position", String.valueOf(position));
intent.putExtras(args);
startActivity(intent);
我的活动代码:
Intent intent = getIntent();
Bundle args = this.getIntent().getExtras();
arrayVehicleList = (ArrayList<ModelVehicleList>)
args.getParcelableArrayListExtra("arrayList");
title = (String) args.getStringExtra("title");
position = (String) args.getStringExtra("position");