写作领域:
Realm realm = Realm.getInstance(mContext);
realm.beginTransaction();
InfoCocktail content = (InfoCocktail) response.body();
realm.copyToRealmOrUpdate(content);
realm.commitTransaction();
realm.close();
阅读时
InfoCocktail cocktail = realm.where(InfoCocktail.class).equalTo("id", mCocktailId).findFirst();
我看到使用调试模式的价值
InfoCocktail = [{id:1},{ingredients:RealmList<Ingredient>[5]},{alc:20},{name:test},{image:http:url},{story:}]
但
所有InfoCocktail字段都为空
我该如何解决这个问题?
public class InfoCocktail extends RealmObject {
@PrimaryKey
private String id;
private RealmList<Ingredient> ingredients;
private String alc;
private String name;
private String image;
private String story;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public RealmList<Ingredient> getIngredients() {
return ingredients;
}
public void setIngredients(RealmList<Ingredient> ingredients) {
this.ingredients = ingredients;
}
....和其他领域的getter和setter
答案 0 :(得分:0)
使用Stirng.valueOf(object.getField())它适用于我
String.valueOf(infoCocktail.getName());