我正在尝试在我的android项目中使用Parceler。 这是我的歌曲模型。
@Parcel(implementations = {SongRealmProxy.class},
value = Parcel.Serialization.BEAN,
analyze = {Song.class})
public class Song extends RealmObject {
@PrimaryKey
public String id;
public String isrc;
public String songName;
public String artistName;
public String album_id;
public String albumArtUrl;
public String genre_id;
public String genreName;
public String releaseYear;
public String price;
public String lyrics;
public String demo;
public int explicit;
}
当我尝试使用这样的捆绑来扭曲这些歌曲模型时。
b.putParcelable(DATA_PARAM, Parcels.wrap(song));
我一直有这个错误。
org.parceler.ParcelerRuntimeException: Unable to find generated Parcelable class for com.devhousemyanmar.juketrill.models.Song, verify that your class is configured properly and that the Parcelable class com.devhousemyanmar.juketrill.models.Song$$Parcelable is generated by Parceler.
请帮我解决这个问题。
答案 0 :(得分:-1)
Parcelable class应该是这样的:
package com.yourpackagename;
public class BrushData implements Parcelable {
public static final Creator<BrushData> CREATOR = new Creator<BrushData>() {
@Override
public BrushData createFromParcel(Parcel in) {
return new BrushData(in);
}
@Override
public BrushData[] newArray(int size) {
return new BrushData[size];
}
};
private static final int VERSION = 1;
@SerializedName("icon")
private String icon;
@SerializedName("effects")
private ArrayList<String> effects;
private BrushData(Parcel parcel) {
if (parcel != null) {
readFromParcel(parcel);
}
}
@Override
public int describeContents() {
return 0;
}
private void readFromParcel(Parcel in) {
if (in.readInt() == VERSION) {
icon = in.readString();
}
}
public void writeToParcel(Parcel parcel, int i) {
parcel.writeInt(VERSION);
parcel.writeString(icon);
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public ArrayList<String> getEffects() {
return effects;
}
public void setEffects(ArrayList<String> effects) {
this.effects = effects;
}
}