java.lang.IllegalStateException: Realm access from incorrect thread. Realm objects can only be accessed on the thread they were created.

tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Threading in Realm - Clean Code Architecture

    Stack Overflow | 7 months ago | Leonardo Ferrari
    java.lang.IllegalStateException: Realm access from incorrect thread. Realm objects can only be accessed on the thread they were created.

    Root Cause Analysis

    1. java.lang.IllegalStateException

      Realm access from incorrect thread. Realm objects can only be accessed on the thread they were created.

      at io.realm.BaseRealm.checkIfValid()
    2. io.realm
      RealmResults.addChangeListener
      1. io.realm.BaseRealm.checkIfValid(BaseRealm.java:456)
      2. io.realm.RealmResults.addChangeListener(RealmResults.java:926)
      2 frames
    3. io.realm.rx
      RealmObservableFactory$5.call
      1. io.realm.rx.RealmObservableFactory$5.call(RealmObservableFactory.java:147)
      2. io.realm.rx.RealmObservableFactory$5.call(RealmObservableFactory.java:131)
      2 frames
    4. rxjava
      ExecutorScheduler$ExecutorSchedulerWorker.run
      1. rx.Observable.unsafeSubscribe(Observable.java:9860)
      2. rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
      3. rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
      4. rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
      5. rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
      6. rx.Observable.unsafeSubscribe(Observable.java:9860)
      7. rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
      8. rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
      9. rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
      10. rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
      11. rx.Observable.unsafeSubscribe(Observable.java:9860)
      12. rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94)
      13. rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
      14. rx.internal.schedulers.ExecutorScheduler$ExecutorSchedulerWorker.run(ExecutorScheduler.java:104)
      14 frames
    5. Java RT
      Thread.run
      1. java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
      2. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
      3. java.lang.Thread.run(Thread.java:841)
      3 frames