Note that there are some explanatory texts on larger screens.

plurals
  1. PONULL value for attributes in Parcelable object. why?
    primarykey
    data
    text
    <p>I have the following <code>Recipe</code> class , which is implementing <code>Parcelable</code> class. But when I pass the object from one class to another the value of its attributes is <code>null</code>. why?</p> <p>Recipe Class:</p> <pre><code>package mobile.bh.classes; import java.util.ArrayList; import mobile.bh.activities.MethodStep; import android.graphics.Bitmap; import android.os.Parcel; import android.os.Parcelable; //simple class that just has one member property as an example public class Recipe implements Parcelable { public int id; public String name; public ArrayList&lt;Ingredient&gt; ingredients; public ArrayList&lt;MethodStep&gt; method; public String comment; public String image; public Bitmap image2; public Recipe(){} /* everything below here is for implementing Parcelable */ // 99.9% of the time you can just ignore this public int describeContents() { return 0; } // write your object's data to the passed-in Parcel public void writeToParcel(Parcel out, int flags) { out.writeInt(id); out.writeString(name); out.writeList(ingredients); out.writeList(method); out.writeString(comment); out.writeString(image); } // this is used to regenerate your object. All Parcelables must have a CREATOR that implements these two methods public static final Parcelable.Creator&lt;Recipe&gt; CREATOR = new Parcelable.Creator&lt;Recipe&gt;() { public Recipe createFromParcel(Parcel in) { return new Recipe(in); } public Recipe[] newArray(int size) { return new Recipe[size]; } }; // example constructor that takes a Parcel and gives you an object populated with it's values private Recipe(Parcel in) { in.writeInt(id); in.writeString(name); in.writeList(ingredients); in.writeList(method); in.writeString(comment); in.writeString(image); } } </code></pre> <p>sending the object though <code>intent</code></p> <pre><code> Intent i = new Intent(context,RecipeInfoActivity.class); i.putExtra("recipeObj", recipe); </code></pre> <p>receiving the object in the other side </p> <pre><code>Recipe p = (Recipe) getIntent().getParcelableExtra("recipeObj"); </code></pre> <p>but the value of <code>p.name</code> is <code>null</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload