Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android getParcelableArrayListExtra返回第二个对象为布尔值false的arraylist_Android_Android Intent_Parcel - Fatal编程技术网

Android getParcelableArrayListExtra返回第二个对象为布尔值false的arraylist

Android getParcelableArrayListExtra返回第二个对象为布尔值false的arraylist,android,android-intent,parcel,Android,Android Intent,Parcel,我希望我能马上给这个问题一个悬赏,我已经被这个问题拖了一天多了 情况有点复杂: 我正在尝试使用intent的附加功能将ArrayList从一个活动发送到另一个活动。如果我在将代码放入intent之后直接调试代码,那么它看起来是正常的: 如果你看手表,你可以看到意图是正确填写 如果ArrayList仅包含一个对象,则所有操作都会正常进行,但如果它包含多个对象,则不会正常进行。然后我得到以下错误: Caused by: java.lang.RuntimeException: Parcel a

我希望我能马上给这个问题一个悬赏,我已经被这个问题拖了一天多了

情况有点复杂:

我正在尝试使用intent的附加功能将ArrayList从一个活动发送到另一个活动。如果我在将代码放入intent之后直接调试代码,那么它看起来是正常的:

如果你看手表,你可以看到意图是正确填写

如果ArrayList仅包含一个对象,则所有操作都会正常进行,但如果它包含多个对象,则不会正常进行。然后我得到以下错误:

   Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@2133e0d8: Unmarshalling unknown type code 6619168 at offset 392
            at android.os.Parcel.readValue(Parcel.java:2032)
            at android.os.Parcel.readListInternal(Parcel.java:2235)
            at android.os.Parcel.readArrayList(Parcel.java:1655)
            at android.os.Parcel.readValue(Parcel.java:1986)
            at android.os.Parcel.readMapInternal(Parcel.java:2226)
            at android.os.Bundle.unparcel(Bundle.java:223)
            at android.os.Bundle.getParcelableArrayList(Bundle.java:1217)
            at android.content.Intent.getParcelableArrayListExtra(Intent.java:4798)
            at nl.raakict.android.spc.SearchMapActivity.onCreate(SearchMapActivity.java:85)
            at android.app.Activity.performCreate(Activity.java:5267)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
            at android.app.ActivityThread.access$700(ActivityThread.java:150)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:5279)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
            at dalvik.system.NativeStart.main(Native Method)
我添加了对象(和同级对象)的代码。请注意,这本书中有一个吸引人的地方,我还有一个实现Parcellable的抽象类:

类订单行:

package nl.raakict.android.spc.Model;

import android.os.Parcel;
import android.os.Parcelable;
import nl.raakict.android.spc.Interface.RenewOrderLinesListener;
import nl.raakict.android.spc.Interface.onApiCompleteListener;

import java.util.ArrayList;
import java.util.List;

public class OrderLine extends BaseModel implements onApiCompleteListener, Parcelable {

    private int ID;
    private int OrderID;
    private String Order_Number;
    private String PartName;
    private String Materiaal;
    private double Thickness;
    private double XSize;
    private double YSize;
    private int Amount;
    private String ImagePath;
    private String PositionNumber;
    private double Weight;
    private String Remark;
    private String BonNumber;
    private int ParentOrderLineID;
    private String ParentAssemblyName;
    private String Barcode;
    private ArrayList<OrderLineOperation> OrderLineOperations;
    private ArrayList<OrderLineLocation> ActiveOrderLineLocations;
    private String StatusColor;
    private boolean Completed;
    private long LocationID;
    private int CustomerID;
    private String CustomerName;
    private OrderLineOperation CurrentOperation;
    private boolean IsTransportReady;
    private String PlanningLocation;
    private transient RenewOrderLinesListener apiCompleteListener;

    public OrderLine(){
        ActiveOrderLineLocations = new ArrayList<OrderLineLocation>();
    }


 // Getters, setters, derived methods of onApiCompleteListener



    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(getID());
        dest.writeString(getPartName());
        dest.writeInt(OrderID);
        dest.writeString(Order_Number);
        if(ActiveOrderLineLocations == null || ActiveOrderLineLocations.isEmpty())
            dest.writeByte((byte) 0);
        else {
            dest.writeByte((byte) 1);
            dest.writeTypedList(ActiveOrderLineLocations);
        }
    }

    public OrderLine(Parcel in) {
        this();
        ID = in.readInt();
        PartName = in.readString();
        OrderID = in.readInt();
        Order_Number = in.readString();
        if(in.readByte() == (byte)1)
            in.readTypedList(ActiveOrderLineLocations, OrderLineLocation.CREATOR);
    }

    /**
     * * This field is needed for Android to be able to * create new objects, individually or as arrays. * * This also means that you can use use the default * constructor to create the object and use another * method to hyrdate it as necessary. * * I just find it easier to use the constructor. * It makes sense for the way my brain thinks ;-) *
     */
    public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
        public OrderLine createFromParcel(Parcel in) {
            return new OrderLine(in);
        }

        public OrderLine[] newArray(int size) {
            return new OrderLine[size];
        }
    };

    public ArrayList<OrderLineLocation> getActiveOrderLineLocations() {
        return ActiveOrderLineLocations;
    }

    public void setActiveOrderLineLocations(ArrayList<OrderLineLocation> activeOrderLineLocations) {
        ActiveOrderLineLocations = activeOrderLineLocations;
    }
}
包nl.raakict.android.spc.Model;
导入android.os.packet;
导入android.os.Parcelable;
导入nl.raakict.android.spc.Interface.RenewOrderLinesListener;
导入nl.raakict.android.spc.Interface.onapiccompleteelistener;
导入java.util.ArrayList;
导入java.util.List;
公共类OrderLine扩展了BaseModel在ApicCompleteListener上的实现,Parcelable{
私有int-ID;
私有int-OrderID;
私有字符串顺序号;
私有字符串部分名;
私有字符串材料;
私人双厚度;
私人双XSize;
私人双保险;
私人整数金额;
私有字符串路径;
私有字符串位置号;
私人双倍重量;
私人字符串注释;
私有字符串编号;
私有int ParentOrderLineID;
私有字符串ParentAssemblyName;
私有字符串条形码;
私有ArrayList OrderLineOperations;
私有ArrayList ActiveOrderLineLocations;
私有字符串状态颜色;
完成私有布尔运算;
私人长地址ID;
私人int客户ID;
私有字符串客户名称;
私有OrderLineOperation-CurrentOperation;
私有布尔型IsTransportReady;
私有字符串规划位置;
私有临时续订OrderlinesListener APICompletListener;
公共秩序线(){
ActiveOrderLineLocations=new ArrayList();
}
//OnApicCompleteListener的getter、setter和派生方法
@凌驾
公共int描述内容(){
返回0;
}
@凌驾
公共无效写入包裹(包裹目的地,内部标志){
dest.writeInt(getID());
dest.writeString(getPartName());
目的写入(订单ID);
目的地记录(订单号);
if(ActiveOrderLineLocations==null | | ActiveOrderLineLocations.isEmpty())
目标写入字节((字节)0);
否则{
目标写入字节((字节)1);
目的地writeTypedList(ActiveOrderLineLocations);
}
}
公共订单线(包裹输入){
这个();
ID=in.readInt();
PartName=in.readString();
OrderID=in.readInt();
Order_Number=in.readString();
if(in.readByte()==(字节)1)
in.readTypedList(ActiveOrderLineLocations、OrderLineLocation.CREATOR);
}
/**
**Android需要此字段才能*创建新对象,单独或作为数组。**这也意味着您可以使用默认的*构造函数创建对象,并根据需要使用另一个*方法对其进行混合。**我只是觉得使用构造函数更容易。*这对我的大脑思维方式很有意义;-)*
*/
public static final Parcelable.Creator=新建Parcelable.Creator(){
公共医嘱行createFromParcel(包裹中){
返回新订单行(在中);
}
公共医嘱行[]新数组(整数大小){
返回新订单行[大小];
}
};
公共阵列列表getActiveOrderLineLocations(){
返回ActiveOrderLineLocations;
}
public void setActiveOrderLineLocations(ArrayList activeOrderLineLocations){
ActiveOrderLineLocations=ActiveOrderLineLocations;
}
}
类OrderLineLocation:

package nl.raakict.android.spc.Model;

import android.os.Parcel;
import android.os.Parcelable;

public class OrderLineLocation extends BaseModel implements Parcelable {

private int ID;
private OrderLine OrderLine;
private int OrderLineID;
private int CurrentAmount;
private LocationBase Location;
private String DateChanged;
private long UserID;
private boolean Archive;
private boolean IsOnStockLocation;
private String SupplierID;
private long LocationID;


@Override
public int describeContents() {
    return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeInt(this.ID);
    if (this.OrderLine != null) {
        dest.writeByte((byte) 1);
        dest.writeParcelable(this.OrderLine, 0);
    } else
        dest.writeByte((byte) 0);
    if (this.Location != null) {
        dest.writeByte((byte) 1);
        dest.writeParcelable(this.Location, 0);
    } else
        dest.writeByte((byte) 0);
    if (this.Location != null)
        dest.writeInt(this.OrderLineID);
    dest.writeInt(this.CurrentAmount);
    dest.writeString(this.DateChanged);
    dest.writeLong(this.UserID);
    dest.writeByte(Archive ? (byte) 1 : (byte) 0);
    dest.writeByte(IsOnStockLocation ? (byte) 1 : (byte) 0);
    dest.writeString(this.SupplierID);
}

public OrderLineLocation() {
}

private OrderLineLocation(Parcel in) {
    this.ID = in.readInt();
    if (in.readByte() == (byte) 1)
        this.OrderLine = in.readParcelable(nl.raakict.android.spc.Model.OrderLine.class.getClassLoader());
    if (in.readByte() == (byte) 1)
        this.Location = in.readParcelable(nl.raakict.android.spc.Model.LocationBase.class.getClassLoader());
    this.OrderLineID = in.readInt();
    this.CurrentAmount = in.readInt();
    this.DateChanged = in.readString();
    this.UserID = in.readLong();
    this.Archive = in.readByte() != (byte) 0;
    this.IsOnStockLocation = in.readByte() != (byte) 0;
    this.SupplierID = in.readString();
}

public static final Parcelable.Creator<OrderLineLocation> CREATOR = new Parcelable.Creator<OrderLineLocation>() {
    public OrderLineLocation createFromParcel(Parcel source) {
        return new OrderLineLocation(source);
    }

    public OrderLineLocation[] newArray(int size) {
        return new OrderLineLocation[size];
    }
};
包nl.raakict.android.spc.Model;
导入android.os.packet;
导入android.os.Parcelable;
公共类OrderLineLocation扩展BaseModel实现Parcelable{
私有int-ID;
专用命令行命令行;
私有int OrderLineID;
私人投资额;
私人地点基地地点;
私有字符串已更改;
私有长用户ID;
私人布尔档案;
私有布尔IsOnStockLocation;
私有字符串供应商ID;
私人长地址ID;
@凌驾
公共int描述内容(){
返回0;
}
@凌驾
公共无效写入包裹(包裹目的地,内部标志){
dest.writeInt(此.ID);
if(this.OrderLine!=null){
目标写入字节((字节)1);
dest.writeparceable(this.OrderLine,0);
}否则
目标写入字节((字节)0);
if(this.Location!=null){
目标写入字节((字节)1);
dest.writeparceable(this.Location,0);
}否则
目标写入字节((字节)0);
if(this.Location!=null)
dest.writeInt(此.OrderLineID);
目的写入(此当前金额);
目的地记录(此日期已更改);
dest.writeLong(this.UserID);
目标写入字节(存档)(字节)1:(字节)0;
目标写入字节(IsOnStockLocation?(字节)1:(字节)0);
dest.writeString(此供应商ID);
}
public OrderLineLocation(){
}
专用OrderLineLocation(包裹在中){
this.ID=in.readInt();
if(in.readByte()==(字节)1)
this.OrderLine=in.readParcelable(nl.raakict.android.spc.Model.OrderLine.class.getClassLoader());
if(in.readByte()==(字节)1)
this.Location=in.readParcelable(nl.raakict.android.spc.Model.LocationBase.class.getClassLoader());
this.OrderLineID=in.readInt();
this.CurrentAmount=in.readInt();
this.DateChanged=in.readString();
this.UserID=in.readLong();
this.Archive=in.readByte()!=(字节)0;
this.IsOnStockLocation=in.readByte()!=(字节)0;
这个,供应
package nl.raakict.android.spc.Model;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.ArrayList;

public abstract class LocationBase extends BaseModel implements Parcelable {

    protected String __type;
    protected long Id;
    protected String Name;
    protected String Barcode;
    protected String Remark;
    protected int Discriminator;
    protected int AmountOfSegments;
    protected ArrayList<Carrier> Carriers;
    protected ArrayList<OrderLineLocation> OrderLineLocations;
    protected ArrayList<Order_Header> Orders;
    protected LocationBase Location;
    protected ArrayList<OrderLineLocation> ActiveLocations;



    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.__type);
        dest.writeLong(this.Id);
        dest.writeString(this.Name);
        dest.writeString(this.Barcode);
        dest.writeString(this.Remark);
        dest.writeInt(this.Discriminator);
        dest.writeInt(this.AmountOfSegments);
        if(this.ActiveLocations == null || this.ActiveLocations.isEmpty())
            dest.writeByte((byte) 0);
        else {
            dest.writeByte((byte) 1);
            dest.writeTypedList(this.ActiveLocations);
        }
        if(this.Orders == null || this.Orders.isEmpty())
            dest.writeByte((byte) 0);
        else {
            dest.writeByte((byte) 1);
            dest.writeTypedList(this.Orders);
        }
    }

    public LocationBase() {
    }


    public static final Parcelable.Creator<LocationBase> CREATOR = new Parcelable.Creator<LocationBase>() {
        public LocationBase createFromParcel(Parcel source) {
            Byte b = source.readByte();
            if(b == 0)
                return nl.raakict.android.spc.Model.Carrier.CREATOR.createFromParcel(source);
            else
                return nl.raakict.android.spc.Model.Location.CREATOR.createFromParcel(source);
        }

        public LocationBase[] newArray(int size) {
            return new LocationBase[size];
        }
    };
}
package nl.raakict.android.spc.Model;

import android.os.Parcel;
import android.os.Parcelable;

public class Carrier extends LocationBase {

    private int LocationID;
    private int CarrierTypeID;
    private boolean CanBePlacedOnCarrier;
    private boolean CanBeCarrierLocation;
    protected int StartSegment;
    private String CarrierTypeName;
    private int NumberOfEdges;
    private transient int Indentation;


    public Carrier() {
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByte((byte) 0);
        super.writeToParcel(dest, flags);
        if (this.Location != null) {
            dest.writeByte((byte) 1);
            dest.writeParcelable(this.Location, 0);
        } else
            dest.writeByte((byte) 0);
    }

    protected Carrier(Parcel in) {
        this.__type = in.readString();
        this.Id = in.readLong();
        this.Name = in.readString();
        this.Barcode = in.readString();
        this.Remark = in.readString();
        this.Discriminator = in.readInt();
        this.AmountOfSegments = in.readInt();
        if(in.readByte() == (byte)1)
            in.readTypedList(ActiveLocations, OrderLineLocation.CREATOR);
        if(in.readByte() == (byte)1)
            in.readTypedList(Orders, Order_Header.CREATOR);
        if (in.readByte() == (byte) 1)
            this.Location = in.readParcelable(nl.raakict.android.spc.Model.LocationBase.class.getClassLoader());
    }

    public static final Parcelable.Creator<LocationBase> CREATOR = new Parcelable.Creator<LocationBase>() {
        public Carrier createFromParcel(Parcel in) {
            return new Carrier(in);
        }

        public Carrier[] newArray(int size) {
            return new Carrier[size];
        }
    };

}
package nl.raakict.android.spc.Model;

import android.os.Parcel;
import android.os.Parcelable;

public class Location extends LocationBase  {

    protected int LocationGroupID;
    protected int PositionZ;

    public Location() {
    }

    protected Location(Parcel in) {
        this.__type = in.readString();
        this.Id = in.readLong();
        this.Name = in.readString();
        this.Barcode = in.readString();
        this.Remark = in.readString();
        this.Discriminator = in.readInt();
        this.AmountOfSegments = in.readInt();
        if(in.readByte() == (byte)1)
            in.readTypedList(ActiveLocations, OrderLineLocation.CREATOR);
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByte((byte) 1);
        super.writeToParcel(dest, flags);
    }

    public static final Parcelable.Creator<LocationBase> CREATOR = new Parcelable.Creator<LocationBase>() {
        public Location createFromParcel(Parcel source) {
            return new Location(source);
        }

        public Location[] newArray(int size) {
            return new Location[size];
        }
    };
}