0

I am trying to pass a Model object containing an arraylist from an activity to another, but it seems like I miss something with the Parcelable class or the intent stuff.

This is the error i get:

java.lang.RuntimeException: Parcel: unable to marshal value Vector3 <x, y, z>: <-0.5, -0.5, 0.0>

Model class

public class Model implements Parcelable{
public List<Stack> surfaces;
public Info info;

public Model(List<Stack> surf){
    surfaces = surf;
}

public void setInfo(Info i){
    info=i;
}

public Info getInfo(){
    return info;
}

public List<Stack> getSurfaces(){
    return surfaces;
}

public int numSurfaces(){
    return surfaces.size();
}

public int describeContents() {
    return 0;
}

public void writeToParcel(Parcel out, int flags) {
    out.writeList(surfaces);
    Parcelable infoP = ((Parcelable) info);
    out.writeParcelable(infoP, 0);
}

public static final Parcelable.Creator<Model> CREATOR
        = new Parcelable.Creator<Model>() {
    public Model createFromParcel(Parcel in) {
        return new Model(in);
    }

    public Model[] newArray(int size) {
        return new Model[size];
    }
};

private Model(Parcel in) {
    surfaces = new ArrayList<Stack>();
    in.readList(surfaces, Stack.class.getClassLoader());
    info = in.readParcelable(Info.class.getClassLoader());
}

public class Info{
    String title;
    String descr;

    public Info(String t, String d){
        title=t;
        descr=d;
    }

    public Info(String t){
        title=t;
    }

    public void setDescr(String d){
        descr=d;
    }
}}

First Activity

...
Model model= new Model(surfaces);

Intent intent = new Intent(this, EditorPresenter.class);
intent.putExtra("model", model);
startActivity(intent);

Second Activity

...
Intent intent = getIntent();
model= intent.getParcelableExtra("points");
surf = model.surfaces.toArray(new Stack[model.numSurfaces()]);
...

Any help much appreciated.

  • what is `Vector3`?. In any case, the error states clearly that the class is not parcelable. – Blackbelt Feb 19 '16 at 14:52
  • 1
    Implement parcelable for other model classes like `Info`, so that you call `Info.CREATOR` when marshalling the `Parcelable` objects of `Model` class. Each model class takes care of its own marshalling and unmarshalling by providing a `Creator` instance. I can provide an example if you need it. – Elvis Chweya Feb 19 '16 at 15:19
  • Vector3 is just a vector class from Rajawali library classes. Btw I will try to implement Parcelable for Info class, but I don't know if I can do the same for Stack since it is a Java class from Android API – Antonio Iacobucci Feb 19 '16 at 15:24

0 Answers0