Passing nested arraylist of object from adapter to activity - android

I was trying to pass arraylist of nested object from a adapter to an activity, and this activity is not the activity from which the adapter is created. I am able to pass integer or any other data to it, but the arraylist of object comes as null.
public class Rate implements Parcelable{
public final static Parcelable.Creator<Rate> CREATOR = new Creator<Rate>() {
#SuppressWarnings({
"unchecked"
})
public Rate createFromParcel(Parcel in) {
return new Rate(in);
}
public Rate[] newArray(int size) {
return (new Rate[size]);
}
};
#SerializedName("header")
#Expose
private String header;
#SerializedName("body")
#Expose
private List<Body> body = null;
#SerializedName("footer")
#Expose
private String footer;
#SerializedName("type")
#Expose
private String rateCardType;
#SerializedName("rules")
#Expose
private List<Rule> rateRules = null;
protected RateCard(Parcel in) {
this.header = ((String) in.readValue((String.class.getClassLoader())));
in.readList(this.body, (Body.class.getClassLoader()));
this.footer = ((String) in.readValue((String.class.getClassLoader())));
this.rateCardType = ((String) in.readValue((String.class.getClassLoader())));
in.readList(this.rateCardRules, (Rule.class.getClassLoader()));
}
public Rate() {
}
public List<Rule> getRateCardRules() {
return rateCardRules;
}
public void setRateCardRules(List<Rule> rateCardRules) {
this.rateCardRules = rateCardRules;
}
public String getHeader() {
return header;
}
public void setHeader(String header) {
this.header = header;
}
public List<Body> getBody() {
return body;
}
public void setBody(List<Body> body) {
this.body = body;
}
public String getFooter() {
return footer;
}
public void setFooter(String footer) {
this.footer = footer;
}
public String getRateCardType() {
return rateCardType;
}
public void setRateCardType(String rateCardType) {
this.rateCardType = rateCardType;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(header);
dest.writeList(body);
dest.writeValue(footer);
dest.writeValue(rateCardType);
dest.writeList(rateCardRules);
}
public int describeContents() {
return 0;
}
}
I want to pass the Rule object arraylist to another activity. My Rule
class is as shown below
public class Rule implements Parcelable{
public final static Parcelable.Creator<Rule> CREATOR = new Creator<Rule>() {
#SuppressWarnings({
"unchecked"
})
public Rule createFromParcel(Parcel in) {
return new Rule(in);
}
public Rule[] newArray(int size) {
return (new Rule[size]);
}
};
#SerializedName("rule")
#Expose
private DataRows ruleData;
#SerializedName("rule_conditions")
#Expose
private List<DataRows> ruleConditions;
#SerializedName("slots")
#Expose
private List<DataRows> slots;
#SerializedName("header")
#Expose
private DataRows header;
protected Rule(Parcel in) {
in.readList(this.ruleConditions, (DataRows.class.getClassLoader()));
in.readList(this.slots, (DataRows.class.getClassLoader()));
this.ruleData = in.readParcelable((DataRows.class.getClassLoader()));
this.header = in.readParcelable((DataRows.class.getClassLoader()));
}
public Rule() {
}
public DataRows getRuleData() {
return ruleData;
}
public void setRuleData(DataRows ruleData) {
this.ruleData = ruleData;
}
public List<DataRows> getRuleConditions() {
return ruleConditions;
}
public void setRuleConditions(List<DataRows> ruleConditions) {
this.ruleConditions = ruleConditions;
}
public List<DataRows> getSlots() {
return slots;
}
public void setSlots(List<DataRows> slots) {
this.slots = slots;
}
public DataRows getHeader() {
return header;
}
public void setHeader(DataRows header) {
this.header = header;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeList(ruleConditions);
dest.writeList(slots);
dest.writeParcelable(ruleData, flags);
dest.writeParcelable(header, flags);
}
public int describeContents() {
return 0;
}
}
My DataRows class
public class DataRows implements Parcelable{
public final static Parcelable.Creator<DataRows> CREATOR = new Creator<DataRows>() {
#SuppressWarnings({
"unchecked"
})
public DataRows createFromParcel(Parcel in) {
return new DataRows(in);
}
public DataRows[] newArray(int size) {
return (new DataRows[size]);
}
};
#SerializedName("key")
#Expose
private String key;
#SerializedName("value")
#Expose
private String value;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
protected DataRows(Parcel in) {
this.key = ((String) in.readValue((String.class.getClassLoader())));
this.value = ((String) in.readValue((String.class.getClassLoader())));
}
public DataRows() {
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(key);
dest.writeValue(value);
}
public int describeContents() {
return 0;
}
}
And this is how I am trying to pass the value
Intent intent = new Intent(context, RulesDetailActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("rules", (ArrayList<? extends Parcelable>) ruleList);
bundle.putInt("current_rule_index", ruleIndex);
startActivity(context, bundle, intent);
I am getting null for the "rules" in the target activity. What is going wrong here. Can someone help.

For these kind of problem i always prefer to use Gson library. Here is my solution for this.
import gson library.
compile 'com.google.code.gson:gson:2.7'
convert your nested Arraylist to string using gson in your adapter class.
Gson gson = new Gson();
Intent intent = new Intent(context, RulesDetailActivity.class);
intent.putExtra("rules", gson.toJson(ruleList);
startActivity(intent);
after then in RulesDetailActivity class do this:
Gson gson = new Gson();
String gson = getIntent().getStringExtra("rules");
Type type = new TypeToken<List<Rule>>() {
}.getType();
ArraList<Rule> rules = gson.fromGson(gson, type);

Related

Accessing and Storing multiple POJO classes in Room

I have Multiple POJO classes as type's for the main POJO class which I am using to parse the json data using Retrofit. So I provided type converters for the first level Pojo but I'm having trouble in reading the stored data because that is not in correct format.
Here is my POJO class
#Entity(tableName = "entry")
public class Entry implements Parcelable {
#NonNull
#PrimaryKey
#SerializedName("id")
private FeedID feedId;
#SerializedName("title")
private Title EntryTitle;
#SerializedName("im:image")
private List<Image> image;
#SerializedName("summary")
private Summary summary;
public Entry(){}
public FeedID getFeedId() {
return feedId;
}
public void setFeedId(FeedID feedId) {
this.feedId = feedId;
}
public Title getEntryTitle() {
return EntryTitle;
}
public void setEntryTitle(Title entryTitle) {
this.EntryTitle = entryTitle;
}
public List<Image> getImage() {
return image;
}
public void setImage(List<Image> image) {
this.image = image;
}
public Summary getSummary() {
return summary;
}
public void setSummary(Summary summary) {
this.summary = summary;
}
#SuppressWarnings("unused")
public static final Parcelable.Creator<Entry> CREATOR = new Parcelable.Creator<Entry>() {
#Override
public Entry createFromParcel(Parcel in) {
return new Entry(in);
}
#Override
public Entry[] newArray(int size) {
return new Entry[size];
}
};
protected Entry(Parcel in) {
feedId = (FeedID) in.readValue(FeedID.class.getClassLoader());
EntryTitle = (Title) in.readValue(Title.class.getClassLoader());
if (in.readByte() == 0x01) {
image = new ArrayList<Image>();
in.readList(image, Image.class.getClassLoader());
} else {
image = null;
}
summary = (Summary) in.readValue(Summary.class.getClassLoader());
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(feedId);
dest.writeValue(EntryTitle);
if (image == null) {
dest.writeByte((byte) (0x00));
} else {
dest.writeByte((byte) (0x01));
dest.writeList(image);
}
dest.writeValue(summary);
}
public class Title implements Parcelable {
private String label;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
#SuppressWarnings("unused")
public final Parcelable.Creator<Title> CREATOR = new Parcelable.Creator<Title>() {
#Override
public Title createFromParcel(Parcel in) {
return new Title(in);
}
#Override
public Title[] newArray(int size) {
return new Title[size];
}
};
protected Title(Parcel in) {
label = in.readString();
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(label);
}
}
public class Image implements Parcelable {
private String label;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
#SuppressWarnings("unused")
public final Parcelable.Creator<Image> CREATOR = new Parcelable.Creator<Image>() {
#Override
public Image createFromParcel(Parcel in) {
return new Image(in);
}
#Override
public Image[] newArray(int size) {
return new Image[size];
}
};
protected Image(Parcel in) {
label = in.readString();
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(label);
}
}
public class Summary implements Parcelable {
private String label;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
#SuppressWarnings("unused")
public final Parcelable.Creator<Summary> CREATOR = new Parcelable.Creator<Summary>() {
#Override
public Summary createFromParcel(Parcel in) {
return new Summary(in);
}
#Override
public Summary[] newArray(int size) {
return new Summary[size];
}
};
protected Summary(Parcel in) {
label = in.readString();
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(label);
}
}
public class FeedID implements Parcelable {
private Attributes attributes;
public Attributes getAttributes() {
return attributes;
}
public void setAttributes(Attributes attributes) {
this.attributes = attributes;
}
#SuppressWarnings("unused")
public final Parcelable.Creator<FeedID> CREATOR = new Parcelable.Creator<FeedID>() {
#Override
public FeedID createFromParcel(Parcel in) {
return new FeedID(in);
}
#Override
public FeedID[] newArray(int size) {
return new FeedID[size];
}
};
protected FeedID(Parcel in) {
attributes = (Attributes) in.readValue(Attributes.class.getClassLoader());
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(attributes);
}
}
public class Attributes implements Parcelable {
#SerializedName("im:id")
private String id;
public String getIm() {
return id;
}
public void setIm(String im) {
this.id = im;
}
#SuppressWarnings("unused")
public final Parcelable.Creator<Attributes> CREATOR = new Parcelable.Creator<Attributes>() {
#Override
public Attributes createFromParcel(Parcel in) {
return new Attributes(in);
}
#Override
public Attributes[] newArray(int size) {
return new Attributes[size];
}
};
protected Attributes(Parcel in) {
id = in.readString();
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(id);
}
}
}
and this is my TypeConverter class
public class RoomTypeConverters {
#TypeConverter
public static String toString(Entry.Title value) {
Gson gson = new Gson();
String json = gson.toJson(value);
return json;
}
#TypeConverter
public static Entry.Title toTitle(String value) {
Type listType = new TypeToken<Entry.Title>() {
}.getType();
return new Gson().fromJson(value, listType);
}
#TypeConverter
public static String toString(Entry.FeedID value) {
Gson gson = new Gson();
String json = gson.toJson(value);
return json;
}
#TypeConverter
public static Entry.FeedID toFeedID(String value) {
Type listType = new TypeToken<Entry.FeedID>() {
}.getType();
return new Gson().fromJson(value, listType);
}
#TypeConverter
public static String toString(Entry.Summary value) {
Gson gson = new Gson();
String json = gson.toJson(value);
return json;
}
#TypeConverter
public static Entry.Summary toSummary(String value) {
Type listType = new TypeToken<Entry.Summary>() {
}.getType();
return new Gson().fromJson(value, listType);
}
#TypeConverter
public static String toString(List<Entry.Image> value) {
Gson gson = new Gson();
String json = gson.toJson(value);
return json;
}
#TypeConverter
public static List<Entry.Image> toImage(String value) {
Type listType = new TypeToken<Entry.Summary>() {
}.getType();
return new Gson().fromJson(value, listType);
}
}
Do I have to create multiple POJO's like that only for one field? Do we have any other alternative?
Yes, to save a POJO you have to define a class for it (either inner or normal class).
But what I understand from your data schema is that you have a possibly complex data store server side and you want to use a subset of that data in your app. Your POJO can be simplified so you can create a Class called EntryRecord for example and define a simple setter and getter for it like this:
#Entity(tableName = "entry")
public class EntryRecord {
#NonNull
#PrimaryKey
#SerializedName("id")
private String feedId;
#SerializedName("title")
private StringEntryTitle;
#SerializedName("im:image")
private String[] image;
#SerializedName("summary")
private String summary;
public EntryRecord(Entry entry){
//Resolve primitive values from Entry class attributes..
}
public Entry getEntry(){
Entry entry = new Entry();
//Resolve entry values from primitive ones...
return entry ;
}
}
, now all you have to do is to use this class to save and restore your data, you can event make your DAO abstract to convert your POJO before save and vice versa.
P.S: if you don't have any use for such complex Schema with so many single variable classes I really advise you to define custom GSON serializer/deserializer to convert the complex POJO to simplified one from the beginning; removing such a complex schema entirely from your code base.
So after a little research I have found a annotation for which if you have multiple inner classes room will take care of it and you don't have to create any TypeConverters for it.
#Embedded Can be used as an annotation on a field of an Entity or Pojo to signal that nested fields (i.e. fields of the annotated field's class) can be referenced directly in the SQL queries.
For example, if you have 2 classes:
public class Coordinates {
double latitude;
double longitude;
}
public class Address {
String street;
#Embedded
Coordinates coordinates;
}
Room will consider latitude and longitude as if they are fields of the Address class when mapping an SQLite row to Address.
Source : Documentation

Android Json parsing with GSON?

I am quite familiar with Json parsing with Gson. I have done Json parsing using Gson but recently i have multiple json objects with response, i am getting little bit stuck with parsing, here is my code,can anyone help me to solve my problem,that where i am doing wrong.
Thanks in advance
Here is my json response :-
Json response
Here is my POGO class of parsing :-
Style Profile.java
public class StyleProfile implements Parcelable {
#SerializedName("user_name")
#Expose
private String user_name;
#SerializedName("user_picture")
#Expose
private String user_picture;
#SerializedName("user_attr")
#Expose
private UserAttrEntity user_attr;
#SerializedName("user_attributes")
#Expose
private UserAttributes userAttributes;
#SerializedName("style_attr")
#Expose
private StyleAttr style_attr;
private StyleAttrEntity style_attrEntity;
private UserAttributesEntity user_attributes;
private String user_style;
#SerializedName("user_background_image")
#Expose
private String userBackgroundImage;
#SerializedName("user_style_message")
#Expose
private String userStyleMessage;
private String user_style_message;
private List<String> style_message;
public StyleProfile() {
}
protected StyleProfile(Parcel in)
{
user_name = in.readString();
user_picture = in.readString();
user_style = in.readString();
// style_message = in.readString();
}
public static final Creator<StyleProfile> CREATOR = new Creator<StyleProfile>() {
#Override
public StyleProfile createFromParcel(Parcel in) {
return new StyleProfile(in);
}
#Override
public StyleProfile[] newArray(int size) {
return new StyleProfile[size];
}
};
public StyleAttr getStyle_attr() {
return style_attr;
}
public void setStyle_attr(StyleAttr style_attr) {
this.style_attr = style_attr;
}
public String getName() {
return user_name;
}
public void setName(String name) {
this.user_name = name;
}
public String getImage() {
return user_picture;
}
public void setImage(String image) {
this.user_picture = image;
}
public UserAttrEntity getUser_attr() {
return user_attr;
}
public void setUser_attributes(UserAttributesEntity user_attributes) {
this.user_attributes = user_attributes;
}
public void setUser_style(String user_style) {
this.user_style = user_style;
}
public String getUser_style() {
return user_style;
}
public List<String> getStyle_message() {
return style_message;
}
public void setStyle_message(List<String> style_message) {
this.style_message = style_message;
}
public String getStyleMessageAsString() {
return TextUtils.join(". ", style_message);
}
public void setUser_style_message(String user_style_message) {
this.user_style_message = user_style_message;
}
public String getUser_style_message() {
return user_style_message;
}
public UserAttributesEntity getUser_attributes() {
return user_attributes;
}
public void setUser_attr(UserAttrEntity user_attr) {
this.user_attr = user_attr;
}
public UserAttributes getUserAttr() {
return userAttributes;
}
public void setUserAttr(UserAttributes userAttr) {
this.userAttributes = userAttr;
}
public UserAttributes getUserAttributes() {
return userAttributes;
}
public void setUserAttributes(UserAttributes userAttributes) {
this.userAttributes = userAttributes;
}
public String getUserStyle() {
return user_style;
}
public void setUserStyle(String userStyle) {
this.user_style = userStyle;
}
public String getUserBackgroundImage() {
return userBackgroundImage;
}
public void setUserBackgroundImage(String userBackgroundImage) {
this.userBackgroundImage = userBackgroundImage;
}
public String getUserStyleMessage() {
return userStyleMessage;
}
public void setUserStyleMessage(String userStyleMessage) {
this.userStyleMessage = userStyleMessage;
}
#Override
public int describeContents() {
return 0;
}
public StyleAttrEntity getStyle_attrEntity() {
return style_attrEntity;
}
public static Creator<StyleProfile> getCREATOR() {
return CREATOR;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(user_name);
dest.writeString(user_picture);
dest.writeParcelable(user_attr, flags);
dest.writeParcelable(style_attr, flags);
dest.writeString(user_style);
}
public void setStyle_attrEntity(StyleAttrEntity style_attrEntity) {
this.style_attrEntity = style_attrEntity;
}
public static class StyleAttr implements Parcelable {
#SerializedName("Edgy")
#Expose
private Integer edgy;
#SerializedName("Feminine")
#Expose
private Integer feminine;
#SerializedName("Fashion Forward")
#Expose
private Integer fashionForward;
#SerializedName("Classic")
#Expose
private Integer classic;
#SerializedName("Casual")
#Expose
private Integer casual;
#SerializedName("Bohemian")
#Expose
private Integer bohemian;
protected StyleAttr(Parcel in) {
edgy = in.readInt();
casual = in.readInt();
classic = in.readInt();
edgy = in.readInt();
fashionForward = in.readInt();
feminine = in.readInt();
}
public static final Creator<StyleAttr> CREATOR = new Creator<StyleAttr>() {
#Override
public StyleAttr createFromParcel(Parcel in) {
return new StyleAttr(in);
}
#Override
public StyleAttr[] newArray(int size) {
return new StyleAttr[size];
}
};
public void setBohemian(int Bohemian) {
this.bohemian = Bohemian;
}
public void setCasual(int Casual) {
this.casual = Casual;
}
public void setClassic(int Classic) {
this.classic = Classic;
}
public void setEdgy(int Edgy) {
this.edgy = Edgy;
}
public void setFashionForward(int FashionForward) {
this.fashionForward = FashionForward;
}
public void setFeminine(int Feminine) {
this.feminine = Feminine;
}
public int getBohemian() {
return bohemian;
}
public int getCasual() {
return casual;
}
public int getClassic() {
return classic;
}
public int getEdgy() {
return edgy;
}
public int getFashionForward() {
return fashionForward;
}
public int getFeminine() {
return feminine;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(bohemian);
dest.writeInt(casual);
dest.writeInt(classic);
dest.writeInt(edgy);
dest.writeInt(fashionForward);
dest.writeInt(feminine);
}
}
}
UserAttrEntity.java
public class UserAttrEntity implements Parcelable {
#SerializedName("Size")
private String Size = "";
#SerializedName("Shape")
private String Shape = "";
#SerializedName("Bottoms Size")
private String Bottoms_Size = "";
#SerializedName("Height")
private String Height = "";
#SerializedName("Shoes Size")
private String Shoes_Size = "";
#SerializedName("Complexion")
private String Face_Color = "";
#SerializedName("Face Shape")
private String Face_Shape = "";
public UserAttrEntity() {
}
protected UserAttrEntity(Parcel in) {
Shape = in.readString();
Size = in.readString();
Bottoms_Size = in.readString();
Height = in.readString();
Shoes_Size = in.readString();
Face_Color = in.readString();
Face_Shape = in.readString();
}
public static final Creator<UserAttrEntity> CREATOR = new Creator<UserAttrEntity>() {
#Override
public UserAttrEntity createFromParcel(Parcel in) {
return new UserAttrEntity(in);
}
#Override
public UserAttrEntity[] newArray(int size) {
return new UserAttrEntity[size];
}
};
public void setShape(String Shape) {
this.Shape = Shape;
}
public void setSize(String Size) {
this.Size = Size.replace("\n", " ");
}
public void setBottoms_Size(String Bottoms_Size) {
this.Bottoms_Size = Bottoms_Size + " Inch";
}
public void setHeight(String Height) {
this.Height = Height;
}
public void setShoes_Size(String Shoes_Size) {
this.Shoes_Size = Shoes_Size;
}
public void setFace_Color(String Face_Color) {
this.Face_Color = Face_Color;
}
public void setFace_Shape(String Face_Shape) {
this.Face_Shape = Face_Shape;
}
public String getShape() {
return Shape;
}
public String getSize() {
return Size;
}
public String getBottoms_Size() {
return Bottoms_Size;
}
public String getHeight() {
return Height;
}
public String getShoes_Size() {
return Shoes_Size;
}
public String getFace_Color() {
return Face_Color;
}
public String getFace_Shape() {
return Face_Shape;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(Shape);
dest.writeString(Size);
dest.writeString(Bottoms_Size);
dest.writeString(Height);
dest.writeString(Shoes_Size);
dest.writeString(Face_Color);
dest.writeString(Face_Shape);
}
}
User AttributesEntity.java
public class UserAttributes {
#SerializedName("Size")
#Expose
private Size size;
#SerializedName("Shape")
#Expose
private Shape shape;
#SerializedName("Bottoms Size")
#Expose
private BottomsSize bottomsSize;
#SerializedName("Height")
#Expose
private Height height;
#SerializedName("Shoes Size")
#Expose
private ShoesSize shoesSize;
#SerializedName("Complexion")
#Expose
private Complexion complexion;
#SerializedName("Face Shape")
#Expose
private FaceShape faceShape;
public Size getSize() {
return size;
}
public void setSize(Size size) {
this.size = size;
}
public Shape getShape() {
return shape;
}
public void setShape(Shape shape) {
this.shape = shape;
}
public BottomsSize getBottomsSize() {
return bottomsSize;
}
public void setBottomsSize(BottomsSize bottomsSize) {
this.bottomsSize = bottomsSize;
}
public Height getHeight() {
return height;
}
public void setHeight(Height height) {
this.height = height;
}
public ShoesSize getShoesSize() {
return shoesSize;
}
public void setShoesSize(ShoesSize shoesSize) {
this.shoesSize = shoesSize;
}
public Complexion getComplexion() {
return complexion;
}
public void setComplexion(Complexion complexion) {
this.complexion = complexion;
}
public FaceShape getFaceShape() {
return faceShape;
}
public void setFaceShape(FaceShape faceShape) {
this.faceShape = faceShape;
}
}
Style Profile.java
Here i am using it like this
Profile profile = gson.fromJson(obj.toString(), Profile.class);
Log.e("", "profile.getStatus() " + profile.getStatus());
mReceiver.onResponse(profile, tag);
Try this way
//Main data
public class MainData{
#SerializedName("status")
#Expose
private String status;
#SerializedName("data")
#Expose
private Data data;
}
//Data
public class Data {
#SerializedName("user_name")
#Expose
private String userName;
#SerializedName("user_picture")
#Expose
private String userPicture;
#SerializedName("user_attr")
#Expose
private UserAttr userAttr;
#SerializedName("user_attributes")
#Expose
private UserAttributes userAttributes;
#SerializedName("style_attr")
#Expose
private StyleAttr styleAttr;
#SerializedName("user_style")
#Expose
private String userStyle;
#SerializedName("user_background_image")
#Expose
private String userBackgroundImage;
#SerializedName("user_style_message")
#Expose
private String userStyleMessage;
}
//user_attr
public class UserAttr {
#SerializedName("user_attr")
private Map<String, String> userAttributes;
public Map<String, String> getUserAttributes() {
return userAttributes;
}
public void setUserAttributes(Map<String, String> userattributes) {
this.userAttributes= userattributes;
}
}
//user_attributes
public class UserAttributes {
#SerializedName("user_attributes")
private Map<String, CommonUserAttributes> userAttributes;
public Map<String, CommonUserAttributes> getUserAttributes() {
return userAttributes;
}
public void setUserAttributes(Map<String, CommonUserAttributes> userattributes) {
this.userAttributes = userattributes;
}
}
//StyleAttr
public class StyleAttr {
#SerializedName("style_attr")
private Map<String, Integer> styleAttributes;
public Map<String, Integer> getStyleAttributes() {
return styleAttributes;
}
public void setStyleAttributes(Map<String, Integer> styleAttributes) {
this.styleAttributes = styleAttributes;
}
}
//CommonUserAttributes
public class CommonUserAttributes {
#SerializedName("user_attr")
private String value;
#SerializedName("que_id")
private String bottmque_id;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getBottmque_id() {
return bottmque_id;
}
public void setBottmque_id(String bottmque_id) {
this.bottmque_id = bottmque_id;
}
}
put your get,set method yourself.

Pass ArrayList of Parcelable objects throws error

I have an object with a couple of Strings, one int and another object which has 4 inner objects. All of them implementing Parcelable. In order to generate the boilerplate code, I used Parcelable plugin from Android studio.
Even though all the objects are parcelable, I'm getting the following error: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: AlbumTrackResponse
Here's how the POJOs look like:
Main object:
public class AlbumTrackResponse implements Parcelable {
private String id;
private String albumId;
private String position;
private String title;
private int rate;
private AllServices services;
public AllServices getServices() {
return services;
}
public void setServices(AllServices services) {
this.services = services;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getAlbumId() {
return albumId;
}
public void setAlbumId(String albumId) {
this.albumId = albumId;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getRate() {
return rate;
}
public void setRate(int rate) {
this.rate = rate;
}
protected AlbumTrackResponse(Parcel in) {
id = in.readString();
albumId = in.readString();
position = in.readString();
title = in.readString();
rate = in.readInt();
services = (AllServices) in.readValue(AllServices.class.getClassLoader());
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(id);
dest.writeString(albumId);
dest.writeString(position);
dest.writeString(title);
dest.writeInt(rate);
dest.writeValue(services);
}
#SuppressWarnings("unused")
public static final Parcelable.Creator<AlbumTrackResponse> CREATOR = new Parcelable.Creator<AlbumTrackResponse>() {
#Override
public AlbumTrackResponse createFromParcel(Parcel in) {
return new AlbumTrackResponse(in);
}
#Override
public AlbumTrackResponse[] newArray(int size) {
return new AlbumTrackResponse[size];
}
};
}
Inner object with 4 objects
public class AllServices implements Parcelable {
private GigRevService gigrev;
private AppleService apple;
private GoogleService google;
private SpotifyService spotify;
protected AllServices(Parcel in) {
gigrev = (GigRevService) in.readValue(GigRevService.class.getClassLoader());
apple = (AppleService) in.readValue(AppleService.class.getClassLoader());
google = (GoogleService) in.readValue(GoogleService.class.getClassLoader());
spotify = (SpotifyService) in.readValue(SpotifyService.class.getClassLoader());
}
#Override
public int describeContents() {
return 0;
}
public GigRevService getGigrev() {
return gigrev;
}
public void setGigrev(GigRevService gigrev) {
this.gigrev = gigrev;
}
public AppleService getApple() {
return apple;
}
public void setApple(AppleService apple) {
this.apple = apple;
}
public GoogleService getGoogle() {
return google;
}
public void setGoogle(GoogleService google) {
this.google = google;
}
public SpotifyService getSpotify() {
return spotify;
}
public void setSpotify(SpotifyService spotify) {
this.spotify = spotify;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(gigrev);
dest.writeValue(apple);
dest.writeValue(google);
dest.writeValue(spotify);
}
#SuppressWarnings("unused")
public static final Parcelable.Creator<AllServices> CREATOR = new Parcelable.Creator<AllServices>() {
#Override
public AllServices createFromParcel(Parcel in) {
return new AllServices(in);
}
#Override
public AllServices[] newArray(int size) {
return new AllServices[size];
}
};
}
The inner objects from here contain just string items.
Here's how I pass the ArrayList to the bundle:
bundle.putParcelableArrayList(MediaPlayerService.TRACK_LIST, trackList);
I'm passing the items from an Activity to a Service. Any ideas why I'm getting this error?
EDIT: Implementation of service classes
public class GoogleService implements Parcelable {
private String name;
private String uri;
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
protected GoogleService(Parcel in) {
name = in.readString();
uri = in.readString();
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeString(uri);
}
#SuppressWarnings("unused")
public static final Parcelable.Creator<GoogleService> CREATOR = new Parcelable.Creator<GoogleService>() {
#Override
public GoogleService createFromParcel(Parcel in) {
return new GoogleService(in);
}
#Override
public GoogleService[] newArray(int size) {
return new GoogleService[size];
}
};
}
This looks extremly strange
this.services = in.readParcelable(getClass().getClassLoader());
You are pointing out to the wrong class loader. You have to use it like this
this.services = (AllServices)in.readParcelable(AllServices.class.getClassLoader());
Besides that, I am always using this site http://www.parcelabler.com/ to quickly generate my Parceables. Or you could use it like this
services = (AllServices) in.readValue(AllServices.class.getClassLoader());
Here:
protected AllServices(Parcel in) { this.gigrev = in.readParcelable(getClass().getClassLoader());
this.apple = in.readParcelable(getClass().getClassLoader());
this.google = in.readParcelable(getClass().getClassLoader());
this.spotify = in.readParcelable(getClass().getClassLoader()); }
Replace it with
protected AllServices(Parcel in) { this.gigrev = in.readParcelable(GigRevService.class.getClassLoader());
this.apple = in.readParcelable(AppleService.class.getClassLoader());
this.google = in.readParcelable(GoogleService.class.getClassLoader());
this.spotify = in.readParcelable(SpotifyService.class.getClassLoader()); }
And replace:
this.services = in.readParcelable(getClass().getClassLoader());
With:
this.services = in.readParcelable(AllServices.class.getClassLoader());
Also can you show the GoogleService etc classes? Each inner object's class must have a Parcelable creator also and implement the Parcelable interface as well.

How to send class object through intent by implement parcable. Unable to marshal value error

I've one class, in which array list is there. How to send it through intent. following i did for my class
public class MakeOrder implements Parcelable {
#SerializedName("refno")
#Expose
private String refno;
#SerializedName("ddesc")
#Expose
private String ddesc;
#SerializedName("free")
#Expose
private String free;
#SerializedName("fgift")
#Expose
private String fgift;
#SerializedName("sgift")
#Expose
private String sgift;
#SerializedName("sandage")
#Expose
private SandageResponse sandage;
#SerializedName("inst")
#Expose
private String inst;
#SerializedName("items")
#Expose
private List<Item> items = new ArrayList<Item>();
#SerializedName("discount")
#Expose
private String discount;
#SerializedName("coupon")
#Expose
private Coupon coupon;
#SerializedName("delivery")
#Expose
private String delivery;
#SerializedName("user")
#Expose
private User user;
#SerializedName("otype")
#Expose
private String otype;
#SerializedName("ptype")
#Expose
private String ptype;
#SerializedName("app_id")
#Expose
private String appId;
#SerializedName("app_key")
#Expose
private String appKey;
#SerializedName("request")
#Expose
private String request;
#SerializedName("tablename")
#Expose
private String tablename;
#SerializedName("staff")
#Expose
private String staff;
public String getTablename() {
return tablename;
}
public void setTablename(String tablename) {
this.tablename = tablename;
}
public String getStaff() {
return staff;
}
public void setStaff(String staff) {
this.staff = staff;
}
public String getRefno() {
return refno;
}
public void setRefno(String refno) {
this.refno = refno;
}
public String getDdesc() {
return ddesc;
}
public void setDdesc(String ddesc) {
this.ddesc = ddesc;
}
public String getFree() {
return free;
}
public void setFree(String free) {
this.free = free;
}
public String getFgift() {
return fgift;
}
public void setFgift(String fgift) {
this.fgift = fgift;
}
public String getSgift() {
return sgift;
}
public void setSgift(String sgift) {
this.sgift = sgift;
}
public SandageResponse getSandage() {
return sandage;
}
public void setSandage(SandageResponse sandage) {
this.sandage = sandage;
}
public String getInst() {
return inst;
}
public void setInst(String inst) {
this.inst = inst;
}
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
public String getDiscount() {
return discount;
}
public void setDiscount(String discount) {
this.discount = discount;
}
public Coupon getCoupon() {
return coupon;
}
public void setCoupon(Coupon coupon) {
this.coupon = coupon;
}
public String getDelivery() {
return delivery;
}
public void setDelivery(String delivery) {
this.delivery = delivery;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getOtype() {
return otype;
}
public void setOtype(String otype) {
this.otype = otype;
}
public String getPtype() {
return ptype;
}
public void setPtype(String ptype) {
this.ptype = ptype;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getAppKey() {
return appKey;
}
public void setAppKey(String appKey) {
this.appKey = appKey;
}
public String getRequest() {
return request;
}
public void setRequest(String request) {
this.request = request;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.refno);
dest.writeString(this.ddesc);
dest.writeString(this.free);
dest.writeString(this.fgift);
dest.writeString(this.sgift);
dest.writeParcelable(this.sandage, flags);
dest.writeString(this.inst);
dest.writeTypedList(this.items);
dest.writeString(this.discount);
dest.writeParcelable(this.coupon, flags);
dest.writeString(this.delivery);
dest.writeParcelable(this.user, flags);
dest.writeString(this.otype);
dest.writeString(this.ptype);
dest.writeString(this.appId);
dest.writeString(this.appKey);
dest.writeString(this.request);
dest.writeString(this.tablename);
dest.writeString(this.staff);
}
public MakeOrder() {
}
protected MakeOrder(Parcel in) {
this.refno = in.readString();
this.ddesc = in.readString();
this.free = in.readString();
this.fgift = in.readString();
this.sgift = in.readString();
this.sandage = in.readParcelable(SandageResponse.class.getClassLoader());
this.inst = in.readString();
this.items = in.createTypedArrayList(Item.CREATOR);
this.discount = in.readString();
this.coupon = in.readParcelable(Coupon.class.getClassLoader());
this.delivery = in.readString();
this.user = in.readParcelable(User.class.getClassLoader());
this.otype = in.readString();
this.ptype = in.readString();
this.appId = in.readString();
this.appKey = in.readString();
this.request = in.readString();
this.tablename = in.readString();
this.staff = in.readString();
}
public static final Parcelable.Creator<MakeOrder> CREATOR = new Parcelable.Creator<MakeOrder>() {
#Override
public MakeOrder createFromParcel(Parcel source) {
return new MakeOrder(source);
}
#Override
public MakeOrder[] newArray(int size) {
return new MakeOrder[size];
}
};
}
Please take a look of updated one
I'm getting error like unable to marshal value
I made all class Parcelable. how to send its object through Intent
Thanks in Advance
Logcat is like
java.lang.RuntimeException: Parcel: unable to marshal value Models.PlaceOrder.Sub#41e10f80
at android.os.Parcel.writeValue(Parcel.java:1235)
at android.os.Parcel.writeList(Parcel.java:622)
at Models.PlaceOrder.Item.writeToParcel(Item.java:90)
at android.os.Parcel.writeTypedList(Parcel.java:1017)
at Models.PlaceOrder.MakeOrder.writeToParcel(MakeOrder.java:246)
at android.os.Parcel.writeParcelable(Parcel.java:1254)
at android.os.Parcel.writeValue(Parcel.java:1173)
at android.os.Parcel.writeMapInternal(Parcel.java:591)
at android.os.Bundle.writeToParcel(Bundle.java:1627)
at android.os.Parcel.writeBundle(Parcel.java:605)
at android.content.Intent.writeToParcel(Intent.java:6866)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1897)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1418)
at android.app.Activity.internalStartActivityForResult(Activity.java:3427)
at android.app.Activity.access$200(Activity.java:660)
at android.app.Activity$2.onStartActivity(Activity.java:3417)
at android.app.Activity.startActivityForBusiness(Activity.java:5441)
at android.app.Activity.startActivityForResult(Activity.java:3413)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
at android.app.Activity.startActivityForResult(Activity.java:3367)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:871)
at android.app.Activity.startActivity(Activity.java:3644)
at android.app.Activity.startActivity(Activity.java:3612)
Items.java where getting Exception
public class Item implements Parcelable {
#SerializedName("itemid")
#Expose
private String itemid;
#SerializedName("qty")
#Expose
private String qty;
#SerializedName("sub")
#Expose
private List<Sub> sub = new ArrayList<Sub>();
/**
*
* #return
* The itemid
*/
public String getItemid() {
return itemid;
}
/**
*
* #param itemid
* The itemid
*/
public void setItemid(String itemid) {
this.itemid = itemid;
}
/**
*
* #return
* The qty
*/
public String getQty() {
return qty;
}
/**
*
* #param qty
* The qty
*/
public void setQty(String qty) {
this.qty = qty;
}
/**
*
* #return
* The sub
*/
public List<Sub> getSub() {
return sub;
}
/**
*
* #param sub
* The sub
*/
public void setSub(List<Sub> sub) {
this.sub = sub;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.itemid);
dest.writeString(this.qty);
dest.writeList(this.sub);
}
public Item() {
}
protected Item(Parcel in) {
this.itemid = in.readString();
this.qty = in.readString();
this.sub = new ArrayList<Sub>();
in.readList(this.sub, Sub.class.getClassLoader());
}
public static final Parcelable.Creator<Item> CREATOR = new Parcelable.Creator<Item>() {
#Override
public Item createFromParcel(Parcel source) {
return new Item(source);
}
#Override
public Item[] newArray(int size) {
return new Item[size];
}
};
}
You need to implement Parcelable also in the Item and Coupon objects.
Then when you add and read the list in you MakeOrder class:
#Override
public void writeToParcel(Parcel dest, int flags) {
...
// to write the Item list
dest.writeList(items);
// to write Coupon object
dest.writeParcelable(coupon, falgs);
}
BTW, your constructor is empty
private MakeOrder(Parcel in) {
...
// to read the Item list
items = new ArrayList<Item>();
in.readList(items, Item.CREATOR);
// to read Coupon object
in.readParcelable(Coupon.CREATOR);
}
This link could help you:
How to make a class with nested objects Parcelable
And this is the Parcelable documentation:
https://developer.android.com/reference/android/os/Parcel.html
EDIT:
The where more Percel problem added to the question.
Final solution in chat: https://chat.stackoverflow.com/rooms/123710/discussion-between-aman-singh-and-adalpari
You need to put in extras like this:
Intent intent-new Intent(this,YouActvity.class);
intent.putExtra("key",yourModel);
startActivity(intent);
In Activity to retrive:
YouModel yourModel = (YourModel) getIntent().getSerializableExtra("key");
Firstly, your Parcelable constructor is empty. If you leave it empty, then it won't work. You need to read fields from parcel the same order you wrote them in writeToParcel() method.
Then to write parcelable data to intent, putExtra() method of the intent. To extract data from intent, use getParcelableExtra() method of the intent
Try using this
intent.putParcelableArrayListExtra("value", orderList);
And in other Activity get it as:
List<String> orderList=this.getIntent().
getParcelableArrayListExtra("value");
Hope this helps

Android Parceable issue

I am currently trying to pass a parceablearraylist from mylogin activity to my main activity but getting a
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.muuves.introround/com.muuves.introround.activities.MainActivity}: java.lang.RuntimeException: Parcel android.os.Parcel#41ef90a8: Unmarshalling unknown type code 7536741 at offset 684
Here are my parceable objects
public class Challenge implements Parcelable {
private Integer id;
private Integer challenger_id;
private Integer friend_id;
private String artist_name;
private String song_name;
private String image_url;
private String song_url;
private String answer_url;
private int challenge_attempts_left;
private int answer;
private Person person;
private Person friend;
public Challenge() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getChallenger_id() {
return challenger_id;
}
public void setChallenger_id(Integer challenger_id) {
this.challenger_id = challenger_id;
}
public Integer getFriend_id() {
return friend_id;
}
public void setFriend_id(Integer friend_id) {
this.friend_id = friend_id;
}
public String getArtist_name() {
return artist_name;
}
public void setArtist_name(String artist_name) {
this.artist_name = artist_name;
}
public String getSong_name() {
return song_name;
}
public void setSong_name(String song_name) {
this.song_name = song_name;
}
public String getImage_url() {
return image_url;
}
public void setImage_url(String image_url) {
this.image_url = image_url;
}
public String getSong_url() {
return song_url;
}
public void setSong_url(String song_url) {
this.song_url = song_url;
}
public String getAnswer_url() {
return answer_url;
}
public void setAnswer_url(String answer_url) {
this.answer_url = answer_url;
}
public int getChallenge_attempts_left() {
return challenge_attempts_left;
}
public void setChallenge_attempts_left(int challenge_attempts_left) {
this.challenge_attempts_left = challenge_attempts_left;
}
public int getAnswer() {
return answer;
}
public void setAnswer(int answer) {
this.answer = answer;
}
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
public Person getFriend() {
return friend;
}
public void setFriend(Person friend) {
this.friend = friend;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeInt(challenger_id);
dest.writeInt(friend_id);
dest.writeString(artist_name);
dest.writeString(image_url);
dest.writeString(song_url);
dest.writeString(answer_url);
dest.writeInt(challenge_attempts_left);
dest.writeInt(answer);
dest.writeParcelable(person, flags);
dest.writeParcelable(friend, flags);
}
public static final Parcelable.Creator<Challenge> CREATOR = new Parcelable.Creator<Challenge>() {
#Override
public Challenge createFromParcel(Parcel in) {
Challenge challenge = new Challenge();
challenge.setId(in.readInt());
challenge.setChallenger_id(in.readInt());
challenge.setFriend_id(in.readInt());
challenge.setArtist_name(in.readString());
challenge.setSong_name(in.readString());
challenge.setImage_url(in.readString());
challenge.setSong_url(in.readString());
challenge.setAnswer_url(in.readString());
challenge.setChallenge_attempts_left(in.readInt());
challenge.setAnswer(in.readInt());
challenge.setPerson((Person) in.readParcelable(Person.class.getClassLoader()));
challenge.setFriend((Person) in.readParcelable(Person.class.getClassLoader()));
return challenge;
}
#Override
public Challenge[] newArray(int size) {
return new Challenge[size];
}
};
}
public class Person implements Parcelable {
private int id;
private String first_name;
private String last_name;
private String image_url;
public Person(){
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getFirst_Name() {
return first_name;
}
public void setFirst_Name(String first_name) {
this.first_name = first_name;
}
public String getLast_Name() {
return last_name;
}
public void setLast_Name(String last_name) {
this.last_name = last_name;
}
public String getImage_url() {
return image_url;
}
public void setImage_url(String image_url) {
this.image_url = image_url;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(first_name);
dest.writeString(last_name);
dest.writeString(image_url);
}
public static final Parcelable.Creator<Person> CREATOR = new Parcelable.Creator<Person>() {
#Override
public Person createFromParcel(Parcel in) {
Person person = new Person();
person.setId(in.readInt());
person.setFirst_Name(in.readString());
person.setLast_Name(in.readString());
person.setImage_url(in.readString());
return person;
}
#Override
public Person[] newArray(int size) {
return null;
}
};
}
Login activity
#Override
public void preLoadDetails(Details details) {
Intent intent = new Intent(this, MainActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("receive", details.getReceive());
intent.putExtras(bundle);
startActivity(intent);
}
MainActivity
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = this.getIntent().getExtras();
ArrayList<Challenge> friends = bundle.getParcelableArrayList("receive");
mContent = new MainFragment(0);
mContent.setArguments(getIntent().getExtras());
// set the Above View
setContentView(R.layout.home_frame);
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, mContent).commit();
// set the Behind View
setBehindContentView(R.layout.menu_frame);
getSupportFragmentManager().beginTransaction()
.replace(R.id.menu_frame, new MenuFragment()).commit();
// Disable
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
}
Been trying to fix it for the pass day and getting no where all I know is that person parceable object in the challenge object are always null but they are not when I put them in the bundle.
Appreciate any input.
Those Integer type could be null or an int, you need to handle that situation properly.
For example I have utility functions like this :
static public Integer readInteger(Parcel in){
if(in.readInt() == 1){
return in.readInt();
}else{
return null;
}
}
static public void writeInteger(Integer value, Parcel out){
if(value != null){
out.writeInt(1);
out.writeInt(value);
}else{
out.writeInt(0);
}
}
First thing in the class Challenge you use Integer attributes and you parce "int" those are 2 diferents things.
Exemple of how i do things myself :
public Podcast(Parcel parcel) {
id = parcel.readLong();
title = parcel.readString();
subtitle = parcel.readString();
summary = parcel.readString();
duration = parcel.readString();
author = parcel.readString();
date = parcel.readString();
mp3 = parcel.readString();
podcastCategoryId = parcel.readLong();
}
#Override
public int describeContents() {
// not used
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeString(title);
dest.writeString(subtitle);
dest.writeString(summary);
dest.writeString(duration);
dest.writeString(author);
dest.writeString(date);
dest.writeString(mp3);
dest.writeLong(podcastCategoryId);
}
public static Creator<Podcast> CREATOR = new Creator<Podcast>() {
public Podcast createFromParcel(Parcel parcel) {
return new Podcast(parcel);
}
public Podcast[] newArray(int size) {
return new Podcast[size];
}
};
#Override
public Person[] newArray(int size) {
return null;
}
You should create there an array of that size and return it.
#Override
public Person[] newArray(int size) {
return new Person[size];
}
Solved it was actually very simple, forgot song url when i was writing to the parcel. Any when i missed that write that was why i was getting the weird exception for person object. it was expecting a person object but was getting something else. 1 day wasted oh well :(
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeInt(challenger_id);
dest.writeInt(friend_id);
dest.writeString(artist_name);
**dest.writeString(song_name);**
dest.writeString(image_url);
dest.writeString(song_url);
dest.writeString(answer_url);
dest.writeInt(challenge_attempts_left);
dest.writeInt(answer);
dest.writeParcelable(person, flags);
dest.writeParcelable(friend, flags);
}

Categories

Resources