Android Using Parcelable gives error : android.os.Parcel unmarshelling unknown type code
public class GalleryDTO implements Parcelable{
private String id;
private String title;
private String date;
private String featuredDesc;
private String bodyText;
private String thumbnailURL;
private String featuredPictureURL;
private String fullPictureURL;
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public GalleryDTO createFromParcel(Parcel in) {
return new GalleryDTO(in);
}
public GalleryDTO[] newArray(int size) {
throw new UnsupportedOperationException();
}
};
public GalleryDTO(){
}
public GalleryDTO(Parcel in){
readFromParcel(in);
}
private void readFromParcel(Parcel in) {
// TODO Auto-generated method stub
id = in.readString();
title = in.readString();
bodyText = in.readString();
thumbnailURL = in.readString();
date = in.readString();
featuredDesc = in.readString();
featuredPictureURL = in.readString();
fullPicture开发者_JAVA百科URL = in.readString();
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getFeaturedDesc() {
return featuredDesc;
}
public void setFeaturedDesc(String featuredDesc) {
this.featuredDesc = featuredDesc;
}
public String getBodyText() {
return bodyText;
}
public void setBodyText(String bodyText) {
this.bodyText = bodyText;
}
public String getThumbnailURL() {
return thumbnailURL;
}
public void setThumbnailURL(String thumbnailURL) {
this.thumbnailURL = thumbnailURL;
}
public String getFeaturedPictureURL() {
return featuredPictureURL;
}
public void setFeaturedPictureURL(String featuredPictureURL) {
this.featuredPictureURL = featuredPictureURL;
}
public String getFullPictureURL() {
return fullPictureURL;
}
public void setFullPictureURL(String fullPictureURL) {
this.fullPictureURL = fullPictureURL;
}
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.id);
dest.writeString(this.bodyText);
dest.writeString(this.date);
dest.writeString(this.featuredDesc);
dest.writeString(this.fullPictureURL);
dest.writeString(this.thumbnailURL);
dest.writeString(this.title);
}
}
i put the parcelable in my activioty here
private ArrayList galleryArray;
public boolean onSearchRequested() {
Bundle appData = new Bundle();
appData.putParcelableArrayList("galleryVector",
(ArrayList<? extends Parcelable>) galleryArray);
startSearch(null, false, appData, false);
return true;
}
in my searchableActivity i did like this
Bundle appData = intent.getBundleExtra(SearchManager.APP_DATA);
if (appData != null) {
galleryItems = appData.getParcelable("galleryVector");
}
and it throws error "android.os.Parcel unmarshelling unknown type code" while getting the parcelable out of the parcel.....
can u help me where i am doing wrong
It seems that you have to use appData.getParcelableArrayList()
instead of appData.getParcelable()
. You are putting in with putParcelableArrayList()
so you have to retrieve the data with the corresponding method, i.e. getParcelableArrayList
.
精彩评论