gpt4 book ai didi

android - 错误的交易状态(没有 Activity 的交易、错误的交易类型或交易已经在进行中)

转载 作者:搜寻专家 更新时间:2023-10-30 20:52:18 26 4
gpt4 key购买 nike

我目前正在为我的应用程序使用 Realm 但是当我读 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)

代码 fragment 是:

 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 类时,它不是空的

最佳答案

所以,我解决了这个问题,当我更清楚地查看 logcat 时,还有一个错误指出我已经有了主键,它又被保存了。所以,我创建了一个新的 realmClass 对象,然后更新了它在里面。

 -->     currentChatRealmModelClass obj=new currentChatRealmModelClass();//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.beginTransaction();
--> realm.copyToRealmOrUpdate(obj);
--> realm2.commitTransaction();

关于android - 错误的交易状态(没有 Activity 的交易、错误的交易类型或交易已经在进行中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37911961/

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