我有 Arraylist 的通用类型。我用过Parcelable
但它总是抛出错误我用过以下代码
内容
public class Content implements Parcelable {
private String pc, cc, sc, uId, name, title, image, image2, url2g, url3g,
urlHd, rating, views, smallDesc, longDesc, dvrId, id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUID() {
return uId;
}
public String getPC() {
return pc;
}
public String getDVRID() {
return dvrId;
}
public void setDVRID(String dVRID) {
dvrId = dVRID;
}
public String getIMAGE2() {
return image2;
}
public void setIMAGE2(String iMAGE2) {
image2 = iMAGE2;
}
public void setPC(String pC) {
pc = pC;
}
public String getCC() {
return cc;
}
public void setCC(String cC) {
cc = cC;
}
public String getSC() {
return sc;
}
public void setSC(String sC) {
sc = sC;
}
public void setUID(String uID) {
uId = uID;
}
public String getNAME() {
return name;
}
public void setNAME(String nAME) {
name = nAME;
}
public String getTITLE() {
return title;
}
public void setTITLE(String tITLE) {
title = tITLE;
}
public String getIMAGE() {
return image;
}
public void setIMAGE(String iMAGE) {
image = iMAGE;
}
public String getURL2G() {
return url2g;
}
public void setURL2G(String uRL2G) {
url2g = uRL2G;
}
public String getURL3G() {
return url3g;
}
public void setURL3G(String uRL3G) {
url3g = uRL3G;
}
public String getURLHD() {
return urlHd;
}
public void setURLHD(String uRLHD) {
urlHd = uRLHD;
}
public String getRATING() {
return rating;
}
public void setRATING(String rATING) {
rating = rATING;
}
public String getVIEWS() {
return views;
}
public void setVIEWS(String vIEWS) {
views = vIEWS;
}
public String getSMALLDESC() {
return smallDesc;
}
public void setSMALLDESC(String sMALLDESC) {
smallDesc = sMALLDESC;
}
public String getLONGDESC() {
return longDesc;
}
public void setLONGDESC(String lONGDESC) {
longDesc = lONGDESC;
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel out, int arg1) {
// TODO Auto-generated method stub
out.writeString(pc);
out.writeString(sc);
out.writeString(cc);
}
public static final Parcelable.Creator<Content> CREATOR = new Parcelable.Creator<Content>() {
public Content createFromParcel(Parcel in) {
return new Content();
}
public Content[] newArray(int size) {
return new Content[size];
}
};
}
并使用以下代码调用传递值
Intent details = new Intent(context, B.class);
details.putExtra("category", LIVE);
details.putParcelableArrayListExtra("arrayList",
showcase);
startActivity(details);
获得价值
category = getIntent().getExtras().getInt("category");
content = getIntent().getParcelableArrayListExtra("arrayList");
日志猫
FATAL EXCEPTION: main
E/AndroidRuntime( 4666): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zengamedia.zengatv/com.zengamedia.zengatv.Details}: java.lang.RuntimeException: Parcel android.os.Parcel@40f6de20: Unmarshalling unknown type code 3014771 at offset 112
E/AndroidRuntime( 4666): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
E/AndroidRuntime( 4666): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
E/AndroidRuntime( 4666): at android.app.ActivityThread.access$600(ActivityThread.java:123)
E/AndroidRuntime( 4666): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
E/AndroidRuntime( 4666): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 4666): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 4666): at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime( 4666): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 4666): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 4666): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime( 4666): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime( 4666): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 4666): Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@40f6de20: Unmarshalling unknown type code 3014771 at offset 112
E/AndroidRuntime( 4666): at android.os.Parcel.readValue(Parcel.java:1921)
E/AndroidRuntime( 4666): at android.os.Parcel.readMapInternal(Parcel.java:2094)
E/AndroidRuntime( 4666): at android.os.Parcel.readHashMap(Parcel.java:1439)
E/AndroidRuntime( 4666): at android.os.Parcel.readValue(Parcel.java:1851)
E/AndroidRuntime( 4666): at android.os.Parcel.readListInternal(Parcel.java:2103)
E/AndroidRuntime( 4666): at android.os.Parcel.readArrayList(Parcel.java:1544)
E/AndroidRuntime( 4666): at android.os.Parcel.readValue(Parcel.java:1875)
E/AndroidRuntime( 4666): at android.os.Parcel.readMapInternal(Parcel.java:2094)
E/AndroidRuntime( 4666): at android.os.Bundle.unparcel(Bundle.java:223)
E/AndroidRuntime( 4666): at android.os.Bundle.getParcelableArrayList(Bundle.java:1202)
E/AndroidRuntime( 4666): at android.content.Intent.getParcelableArrayListExtra(Intent.java:4005)
E/AndroidRuntime( 4666): at com.zengamedia.zengatv.Details.onCreate(Details.java:50)
E/AndroidRuntime( 4666): at android.app.Activity.performCreate(Activity.java:4492)
E/AndroidRuntime( 4666): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
E/AndroidRuntime( 4666): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
E/AndroidRuntime( 4666): ... 11 more
请建议我在哪里做错了