坚持设置 Room 以使用 RxJava:访问数据库可能会锁定 UI

所以我试图了解如何反应以及如何使用 Room 库,但我遇到了一些异常,我不知道如何解决:


08-11 20:35:44.349 8797-8797/ru.android_school.h_h.eightapp W/System.err: io.reactivex.exceptions.OnErrorNotImplementedException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.

    at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)

    at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:701)

    at io.reactivex.internal.subscribers.LambdaSubscriber.onError(LambdaSubscriber.java:79)

    at io.reactivex.internal.subscribers.LambdaSubscriber.onNext(LambdaSubscriber.java:69)

08-11 20:35:44.350 8797-8797/ru.android_school.h_h.eightapp W/System.err:     at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.onNext(FlowableSubscribeOn.java:97)

    at io.reactivex.internal.operators.flowable.FlowableObserveOn$ObserveOnSubscriber.runAsync(FlowableObserveOn.java:400)

    at io.reactivex.internal.operators.flowable.FlowableObserveOn$BaseObserveOnSubscriber.run(FlowableObserveOn.java:176)

    at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:109)

    at android.os.Handler.handleCallback(Handler.java:808)

    at android.os.Handler.dispatchMessage(Handler.java:101)

    at android.os.Looper.loop(Looper.java:166)

    at android.app.ActivityThread.main(ActivityThread.java:7425)

    at java.lang.reflect.Method.invoke(Native Method)

    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)

    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

Caused by: java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.


噜噜哒
浏览 473回答 3
3回答

猛跑小猪

异常不是由这段代码引起的。问题出在方法 insert() 和 getBySearch() 中,我没有在问题中指定。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java