gpt4 book ai didi

RealmObject 返回空字段

转载 作者:行者123 更新时间:2023-12-02 11:36:11 24 4
gpt4 key购买 nike

写入 Realm :

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();

我看到使用 Debug模式的值(value)

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

最佳答案

使用 Stirng.valueOf(object.getField()) 它对我有用

String.valueOf(infoCocktail.getName());

关于RealmObject 返回空字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33962125/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com