Ho visto molti esempi parcellari finora, ma per qualche motivo non riesco a farlo funzionare quando diventa un po 'più complesso. Ho un oggetto Movie, che implementa Parcelable. Questo oggetto libro contiene alcune proprietà, come ArrayLists. L'esecuzione della mia app risulta in NullPointerException quando si esegue ReadTypedList! Sono davvero a corto di idee quiArraylist in oggetto parcellizzabile
public class Movie implements Parcelable{
private int id;
private List<Review> reviews
private List<String> authors;
public Movie() {
reviews = new ArrayList<Review>();
authors = new ArrayList<String>();
}
public Movie (Parcel in) {
readFromParcel(in);
}
/* getters and setters excluded from code here */
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeList(reviews);
dest.writeStringList(authors);
}
public static final Parcelable.Creator<Movie> CREATOR = new Parcelable.Creator<Movie>() {
public MoviecreateFromParcel(Parcel source) {
return new Movie(source);
}
public Movie[] newArray(int size) {
return new Movie[size];
}
};
/*
* Constructor calls read to create object
*/
private void readFromParcel(Parcel in) {
this.id = in.readInt();
in.readTypedList(reviews, Review.CREATOR); /* NULLPOINTER HERE */
in.readStringList(authors);
}
}
La classe Review:
public class Review implements Parcelable {
private int id;
private String content;
public Review() {
}
public Review(Parcel in) {
readFromParcel(in);
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(content);
}
public static final Creator<Review> CREATOR = new Creator<Review>() {
public Review createFromParcel(Parcel source) {
return new Review(source);
}
public Review[] newArray(int size) {
return new Review[size];
}
};
private void readFromParcel(Parcel in) {
this.id = in.readInt();
this.content = in.readString();
}
}
sarei molto grato se qualcuno potesse solo io ottenere sulla strada giusta, ho spendere un po 'di tempo cercando questo!
Grazie a adnvance Wesley
Grazie così MUUUUUCH, ho sprecato 2 giorni su questo :-). – Wesley