when try send object activity
, shows error:
java.lang.runtimeexception: unable start activity componentinfo{com.example.android.movieapp/com.example.android.movieapp.detailactivity}: android.os.badparcelableexception: parcelable protocol requires creator object static on class com.example.android.movieapp.movie
this code:
public class movie implements parcelable{ string title; string image; public movie (string title, string image){ this.title = title; this.image = image; } public movie(jsonobject movie) throws jsonexception { this.title = movie.getstring("original_title"); this.image = movie.getstring("poster_path"); } private movie (parcel in){ title = in.readstring(); image = in.readstring(); } public final parcelable.creator<movie> creator = new parcelable.creator<movie>(){ @override public movie createfromparcel(parcel parcel) { return new movie(parcel); } @override public movie[] newarray(int i) { return new movie[i]; } }; @override public string tostring() { return title + "--" + image; } @override public int describecontents() { return 0; } @override public void writetoparcel(parcel dest, int flags) { dest.writestring(title); dest.writestring(image); } public string getimage() { return image; } public string gettitle() { return title; }
}
main class:
public void onitemclick(adapterview<?> parent, view view, int position, long id) { movie movie = movieadapter.getitem(position); intent intent = new intent(getapplication(), detailactivity.class); intent.putextra("send", movie); startactivity(intent); } }); }
and detailclass:
movie movie; bundle extras = getintent().getextras(); movie = extras.getparcelable("send"); title.settext(movie.title);
the exception states:
...the creator object static on class com.example.android.movieapp.movie
also, parcelable documentation:
classes implementing parcelable interface must have non-null static field called creator of type implements parcelable.creator interface.
creator
has static:
public static final parcelable.creator<movie> creator =
Comments
Post a Comment