[英]java.lang.IllegalArgumentException: JSON object doesn't have the primary key field 'id'
I use realm to parse this JSON, but I get this error: java.lang.IllegalArgumentException: JSON object doesn't have the primary key field 'id'. 我使用领域来解析此JSON,但出现以下错误: java.lang.IllegalArgumentException:JSON对象没有主键字段“ id”。
this is my method : 这是我的方法:
Realm r = Realm.getDefaultInstance();
r.beginTransaction();
r.createOrUpdateObjectFromJson(Application.class,result);
r.commitTransaction();
my Application class is : 我的应用程序类是:
public class Application extends RealmObject {
@PrimaryKey
private int id;
private RealmList<girl> girls;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public RealmList<girl> getGirls() {
return girls;
}
public void setGirls(RealmList<girl> girls) {
this.girls = girls;
}
public Application() {
}
public Application(int id, RealmList<girl> girls) {
this.id = id;
this.girls = girls;
}
}
my class girl is 我班上的女孩是
public class girl extends RealmObject {
@PrimaryKey
private int id;
private String name;
private String ville;
private String tel;
private String photo;
//getters and setters and constructors with and without params
}
try to use realm.copyFromRealm();
尝试使用realm.copyFromRealm();
and for more refer bellow link 有关更多信息,请参见波纹管链接
https://github.com/realm/realm-java/issues/1973 https://github.com/realm/realm-java/issues/1973
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.