1

我尝试传递一个带有整数数组列表的可打包对象,但是当 android 尝试读取可打包对象时出现错误

 03-31 19:20:12.484: E/AndroidRuntime(21448): Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@4172c410: Unmarshalling unknown type code 7602291 at offset 192
03-31 19:20:12.484: E/AndroidRuntime(21448):    at android.os.Parcel.readValue(Parcel.java:2032)
03-31 19:20:12.484: E/AndroidRuntime(21448):    at android.os.Parcel.readListInternal(Parcel.java:2235)
03-31 19:20:12.484: E/AndroidRuntime(21448):    at android.os.Parcel.readList(Parcel.java:1531)

这是我的可包裹对象

public class Country implements Parcelable {

    private String name;
    private int id;
    private List<Integer> listTest;


     public Country () {
            super();
            listTest= new ArrayList<Integer>();
        }


    public Country (String name, int id, List <Integer> listTest) {
        super();
        this.name= name;
        this.id=id;
        this.listTest= listTest;
    }

public Country (Parcel in) {

        this.name= in.readString();
        this.id= in.readInt();
        in.readList(listTest,Integer.class.getClassLoader());//error here

    }

    //getters,setters

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

                @Override
                public Country [] newArray(int size)
                {
                return new Country [size];
                }
            };


@Override
public int describeContents() {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeString(name);
    dest.writeInt(id);
    dest.writeList(listTest);


}

}

我检查了我的列表,它只包含整数,所以我不知道这个错误来自哪里

非常感谢您的帮助

4

1 回答 1

2

我改变

in.readList(listTest,List.class.getClassLoader());  

我没有错误。

于 2013-03-31T19:08:04.247 回答