尝试将模型类arrayList传递给片段中的活动时出错?

问题描述 投票:-2回答:1

从Fragment传递ArrayList到Activity时抛出错误。我从来没有遇到过这种错误。只有当我将ArrayList传递给Activity时才会抛出错误。我已经搜索但是我没有得到解决问题的答案。你能检查我的代码,告诉我是否有任何错误。

java.lang.RuntimeException:Parcel android.os.Parcel@c154e0a:在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)的android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)偏移884处解组未知类型代码101 :2988)在Android.app.Handler.dispatchMessage(Handler.java:102)的android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1631)的android.app.ActivityThread.-wrap14(ActivityThread.java) android.os.Looper.loop(Looper.java:154)位于com.android.internal的java.lang.reflect.Method.invoke(Native Method)的android.app.ActivityThread.main(ActivityThread.java:6682)。 os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1520)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)引起:java.lang.RuntimeException:Parcel android.os.Parcel@c154e0a :在Android的android.os.Parcel.readArrayMapInternal(Parcel.java:2727)的android.os.Parcel.readValue(Parcel.java:2453)的偏移884处解组未知类型代码101。 os.BaseBundle.unparcel(BaseBundle.java:269)位于android.os.BaseBundle.getSerializable(BaseBundle.java:1064),位于com.iroid.uiic.ui的android.os.Bundle.getSerializable(Bundle.java:934)在Android的android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)的android.app.Activity.performCreate(Activity.java:6942)上的.main.vehiclelist.vehicle_detail_view.VehicleDetailViewActivity.onCreate(VehicleDetailViewActivity.java:39)。 app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)位于android.app.A活动中的android.app.A活动时,活动强化(ActivityThread.java:2988)android.app.A活动。 handleMessage(ActivityThread.java:1631)位于android.app.AtoT.Thread.main上的android.os.Handler.dispatchMessage(Handler.java:102)android.os.Looper.loop(Looper.java:154)(ActivityThread.java) :6682)at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(Zy)java.lang.reflect.Method.invoke(Native Method) goteInit.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;
    }
}
android arraylist
1个回答
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");
© www.soinside.com 2019 - 2024. All rights reserved.