Any idea on why this would be happening?
java.lang.IllegalStateException: The Realm is already in a write transaction in /Users/zaki/fromgit/realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 113
at io.realm.internal.SharedRealm.nativeBeginTransaction(Native Method)
at io.realm.internal.SharedRealm.beginTransaction(SharedRealm.java:219)
at io.realm.BaseRealm.beginTransaction(BaseRealm.java:328)
at io.realm.Realm.beginTransaction(Realm.java:127)
Realm version(s): 2.1.1
Android Studio version: 2.2.2
Which Android version and device: Android 4.4
Device : Wish Tel - Ira thing 2
You probably called beginTransaction() twice on the same thread without calling either cancelTransaction or commitTransaction
@Zhuinden But its happening on only one particular above mentioned device
You probably ran into an exception on a thread pool during transaction and didn't cancel the transaction when it happened, so the next execution on that thread was still in a transaction.
You should use executeTransaction instead.
I know this is closed. But for the same error, I thought to mention my case here. I am using executeTransaction everywhere in my code of access to realm transactions, but yet for a recycler view data, two execute transaction are crashing my app with the same error. Any idea why would it be happening. Currently using realm-gradle plugin 3.4
@preyesm well you can't start a transaction while you're already in a transaction. You should check in your code why you can end up with a transaction inside a transaction.
@Zhuinden There is no instance where I start another transaction within a transaction, I am initiating two separate transactions and both are execute transaction and I end up with The Realm is already in a write transaction in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 263 error.
If you can provide a sample project that reproduces this (or send the APK to help at realm.io) then more can be done.
@Zhuinden : Any update on my query I'm getting same issue.
@Vaishnavi-optisol this tends to happen if you are adding a change listener to something, inside another change listener; and the change listener is invoked by synchronous transaction on the UI thread.
@Zhuinden Hey i am not calling twice please look in to this . and i change all version and error is same please give me suggestion .
I am using this in Kotlin
in this code i am using realm 3.4.0
`
realm?.executeTransaction({ it :
try {
Log.v("realm.isInTransaction()","check 222"+it?.isInTransaction)
if (it?.isInTransaction!!){
**it!!.beginTransaction()**
val student = it!!.createObject(LoginUser::class.java, UUID.randomUUID().toString())
student?.user = (result!!.user)
it!!.commitTransaction()
}
}catch (e:Exception){
Log.v("errr","error "+e.message)
}
})`
ERROR :
ThrowingException 8, The Realm is already in a write transaction in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 263
Well that menas when you are calling realm.executeTransaction, the Realm on that thread is already in a write transaction
Most helpful comment
You probably ran into an exception on a thread pool during transaction and didn't cancel the transaction when it happened, so the next execution on that thread was still in a transaction.
You should use
executeTransactioninstead.