После обновления Realm от 1.1.0
до 2.0.2
. Я получаю эту ошибку во время транзакции объекта. В более ранней версии он работал нормально.
io.realm.exceptions.RealmException: "RealmNoticeModelClass" имеет первичный ключ, вместо этого используйте "createObject (класс, объект)".
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rana.sahaj.myyu, PID: 20202
io.realm.exceptions.RealmException: 'RealmNoticeModelClass' has a primary key, use 'createObject(Class<E>, Object)' instead.
at io.realm.Realm.createObjectInternal(Realm.java:821)
at io.realm.Realm.createObject(Realm.java:802)
at com.rana.sahaj.myyu.notice.NoticeOnItemSelectedActivity$1$2.onSuccess(NoticeOnItemSelectedActivity.java:162)
at com.rana.sahaj.myyu.notice.NoticeOnItemSelectedActivity$1$2.onSuccess(NoticeOnItemSelectedActivity.java:156)
at com.google.android.gms.tasks.zze$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5052)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Код
realm.beginTransaction();
RealmNoticeModelClass realmNoticeModelClass = realm.createObject(RealmNoticeModelClass.class);
realmNoticeModelClass.setDocUrl(DocUrl1);
realmNoticeModelClass.setHashname(heading);
realmNoticeModelClass.setContent(contentString);
realmNoticeModelClass.setTime(getIntent().getExtras().getString("notice_time"));
realmNoticeModelClass.setPicurl(picUrlName);
realmNoticeModelClass.setUserPic(getIntent().getExtras().getString("image_user_notice"));
realmNoticeModelClass.setPdfUrl(PdfUrl);
realmNoticeModelClass.setPicOffline(SnapshotKey);
realmNoticeModelClass.setMetaType(null);
realmNoticeModelClass.setTimeStamp(SnapshotKey);
realm.commitTransaction();
n RealmNoticeModelClass
public class RealmNoticeModelClass extends RealmObject {
@PrimaryKey
private String timeStamp;
private String Content;
@Index
private String UserPic;
private String Hashname;
private String picurl;
private String time;
private String picOffline;
private String pdfUrl;
private String docUrl1;
private String metaType;
public String getMetaType() {
return metaType;
}
public void setMetaType(String metaType) {
this.metaType = metaType;
}
public String getDocUrl() {
return docUrl1;
}
... other getters setters
}