我目前正在为我的应用程序使用领域,但是当我读取 n 写入此错误显示时,我已经检查了两者beginTransaction()
并且commitTransaction()
也正确使用但它仍然显示
错误:
io.realm.exceptions.RealmError: Unrecoverable error. Wrong transactional state (no active transaction, wrong type of transaction, or transaction already in progress) in io_realm_internal_SharedGroup.cpp line 157
at io.realm.internal.SharedGroup.nativeAdvanceRead(Native Method)
at io.realm.internal.SharedGroup.advanceRead(SharedGroup.java:83)
at io.realm.internal.ImplicitTransaction.advanceRead(ImplicitTransaction.java:35)
at io.realm.internal.SharedGroupManager.advanceRead(SharedGroupManager.java:76)
at io.realm.HandlerController.realmChanged(HandlerController.java:384)
at io.realm.HandlerController.handleMessage(HandlerController.java:116)
at android.os.Handler.dispatchMessage(Handler.java:98)
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)
代码片段是:
HashMap<String,String> msg = (HashMap)dataSnapshot.getValue();
Message message = new Message();
message.setSender(msg.get(COLUMN_SENDER));
message.setText(msg.get(COLUMN_TEXT));
message.setTime(msg.get(COLUMN_TIME));
message.setStatus(msg.get(COLUMN_STATUS));
try {
Realm realm = Realm.getInstance(realmConfig);
Realm realm2 = Realm.getInstance(realmConfig);
message.setDate(sDateFormat.parse(SnapshotKey));
// Hawk.put(SnapshotKey, message);
RealmResults<MessageRealm> result = realm.where(MessageRealm.class)
.equalTo("key", SnapshotKey)
.findAll();
if (result.size()==0){
realm.beginTransaction();
MessageRealm messageRealm=realm.createObject(MessageRealm.class);
messageRealm.setSender(msg.get(COLUMN_SENDER));
messageRealm.setText(msg.get(COLUMN_TEXT));
messageRealm.setStatus(msg.get(COLUMN_STATUS));
messageRealm.setTime(msg.get(COLUMN_TIME));
messageRealm.setKey(SnapshotKey);
messageRealm.setChatWith(ReciOtherEmail);
realm.commitTransaction();
String userEmailKeyY=ReciOtherEmail;
String keyEmail=userEmailKeyY;
Log.e("SahajLOG5", "KeyEmail " + userEmailKeyY);
Log.e("SahajLOG", "REALM ADDED TRANSACTION INITIATED ");
RealmResults<ToTal_ProfileModelRealmClass> resultForProfileInfo = realm2.where(ToTal_ProfileModelRealmClass.class)
.equalTo("userEmailKey", keyEmail)
.findAll();
Log.e("SahajLOGL", "REALM REsult <--CorrectionLegacy--> " + resultForProfileInfo);
if(resultForProfileInfo.size()!=0){
--> realm2.beginTransaction();
--> currentChatRealmModelClass obj=realm.createObject(currentChatRealmModelClass.class);
--> obj.setUserEmailKey(keyEmail);
--> obj.setMessage(msg.get(COLUMN_TEXT));
--> obj.setHashname(resultForProfileInfo.get(0).getHashname());
--> obj.setUserNAME(resultForProfileInfo.get(0).getUserNAME());
--> obj.setPicOfllineName(resultForProfileInfo.get(0).getPicOfflineName());
--> obj.setPicurl(resultForProfileInfo.get(0).getPicurl());
--> realm2.commitTransaction();
}
}
}catch (Exception e){
Log.d(TAG, "Couldn't parse data in MessageDataSource Class " + e);
}
if(callbacks != null){
callbacks.onMessageAdded(message);
}
我已经标记了-->
它实际发生的位置。
n 当我登录resultForProfileInfo
课程时,它不为空