android - Send generic type arraylist data from one to another activity -
i have generic tyeps of arraylist.i have used parcelable
but throw error have used following code
content
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]; } }; }
and calling passing values using following code
intent details = new intent(context, b.class); details.putextra("category", live); details.putparcelablearraylistextra("arraylist", showcase); startactivity(details);
getting value
category = getintent().getextras().getint("category"); content = getintent().getparcelablearraylistextra("arraylist");
logcat
fatal exception: main e/androidruntime( 4666): java.lang.runtimeexception: unable start activity componentinfo{com.zengamedia.zengatv/com.zengamedia.zengatv.details}: java.lang.runtimeexception: parcel android.os.parcel@40f6de20: unmarshalling unknown type code 3014771 @ offset 112 e/androidruntime( 4666): @ android.app.activitythread.performlaunchactivity(activitythread.java:1956) e/androidruntime( 4666): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1981) e/androidruntime( 4666): @ android.app.activitythread.access$600(activitythread.java:123) e/androidruntime( 4666): @ android.app.activitythread$h.handlemessage(activitythread.java:1147) e/androidruntime( 4666): @ android.os.handler.dispatchmessage(handler.java:99) e/androidruntime( 4666): @ android.os.looper.loop(looper.java:137) e/androidruntime( 4666): @ android.app.activitythread.main(activitythread.java:4424) e/androidruntime( 4666): @ java.lang.reflect.method.invokenative(native method) e/androidruntime( 4666): @ java.lang.reflect.method.invoke(method.java:511) e/androidruntime( 4666): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) e/androidruntime( 4666): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) e/androidruntime( 4666): @ dalvik.system.nativestart.main(native method) e/androidruntime( 4666): caused by: java.lang.runtimeexception: parcel android.os.parcel@40f6de20: unmarshalling unknown type code 3014771 @ offset 112 e/androidruntime( 4666): @ android.os.parcel.readvalue(parcel.java:1921) e/androidruntime( 4666): @ android.os.parcel.readmapinternal(parcel.java:2094) e/androidruntime( 4666): @ android.os.parcel.readhashmap(parcel.java:1439) e/androidruntime( 4666): @ android.os.parcel.readvalue(parcel.java:1851) e/androidruntime( 4666): @ android.os.parcel.readlistinternal(parcel.java:2103) e/androidruntime( 4666): @ android.os.parcel.readarraylist(parcel.java:1544) e/androidruntime( 4666): @ android.os.parcel.readvalue(parcel.java:1875) e/androidruntime( 4666): @ android.os.parcel.readmapinternal(parcel.java:2094) e/androidruntime( 4666): @ android.os.bundle.unparcel(bundle.java:223) e/androidruntime( 4666): @ android.os.bundle.getparcelablearraylist(bundle.java:1202) e/androidruntime( 4666): @ android.content.intent.getparcelablearraylistextra(intent.java:4005) e/androidruntime( 4666): @ com.zengamedia.zengatv.details.oncreate(details.java:50) e/androidruntime( 4666): @ android.app.activity.performcreate(activity.java:4492) e/androidruntime( 4666): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1049) e/androidruntime( 4666): @ android.app.activitythread.performlaunchactivity(activitythread.java:1920) e/androidruntime( 4666): ... 11 more
please suggest me i'm doing wrong
your parcelable implementation not correct.
take @ great tool: parcelabler
it type annoying code it, long don't have more complicated types in class. copy-paste whole class in it.
seems tool bit corky spacing , creating multiple strings. should work;
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; } 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]; } }; protected content(parcel in) { pc = in.readstring(); cc = in.readstring(); sc = in.readstring(); uid = in.readstring(); name = in.readstring(); title = in.readstring(); image = in.readstring(); image2 = in.readstring(); url2g = in.readstring(); url3g = in.readstring(); urlhd = in.readstring(); rating = in.readstring(); views = in.readstring(); smalldesc = in.readstring(); longdesc = in.readstring(); dvrid = in.readstring(); id = in.readstring(); } public int describecontents() { return 0; } public void writetoparcel(parcel dest, int flags) { dest.writestring(pc); dest.writestring(cc); dest.writestring(sc); dest.writestring(uid); dest.writestring(name); dest.writestring(title); dest.writestring(image); dest.writestring(image2); dest.writestring(url2g); dest.writestring(url3g); dest.writestring(urlhd); dest.writestring(rating); dest.writestring(views); dest.writestring(smalldesc); dest.writestring(longdesc); dest.writestring(dvrid); dest.writestring(id); } public static final parcelable.creator<content> creator = new parcelable.creator<content>() { public content createfromparcel(parcel in) { return new content(in); } public content[] newarray(int size) { return new content[size]; } };
}
Comments
Post a Comment