我是新来的。我正在尝试使用适用于 Android 的 RxJava 库,但出现错误。逻辑是处理按钮上的点击事件,然后将其映射到从 获取值EditText,然后通过网络将flatmap其解析为值。Single<String>我尝试flatmap使用 IO 线程运行Schedulers.io(),但出现错误:
E/MainActivity: Login error
java.lang.IllegalStateException: Expected to be called on the main thread but was RxCachedThreadScheduler-1
at com.jakewharton.rxbinding3.internal.Preconditions.checkMainThread(mainThread.kt:28)
at com.jakewharton.rxbinding3.view.ViewClickObservable.subscribeActual(ViewClickObservable.kt:35)
at io.reactivex.Observable.subscribe(Observable.java:12267)
at io.reactivex.internal.operators.observable.ObservableMap.subscribeActual(ObservableMap.java:32)
at io.reactivex.Observable.subscribe(Observable.java:12267)
at io.reactivex.internal.operators.observable.ObservableFilter.subscribeActual(ObservableFilter.java:30)
at io.reactivex.Observable.subscribe(Observable.java:12267)
at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
at io.reactivex.Observable.subscribe(Observable.java:12267)
at io.reactivex.internal.operators.observable.ObservableMap.subscribeActual(ObservableMap.java:32)
at io.reactivex.Observable.subscribe(Observable.java:12267)
at io.reactivex.internal.operators.observable.ObservableFlatMapSingle.subscribeActual(ObservableFlatMapSingle.java:48)
at io.reactivex.Observable.subscribe(Observable.java:12267)
有人可以帮我解决这个问题吗?我需要在后台线程上运行网络调用,但在主线程上接收结果。
翻翻过去那场雪
相关分类