I'm trying to observe observable on main thread by using:
// Kotlin Code
Observable
.observeOn(AndroidSchedulers.mainThread())
but I'm getting following error:
Type Mismatch:
Required: rx.Scheduler!
Found: io.reactivex.Scheduler!
The Observable I'm subscribing to is from a Library that is written in Java and therefore uses RxJava.
Am i being stupid and missing something? I'm puzzeled :$
Thanks in advance :)
Required: rx.Scheduler!
Required
means the signature is Observable.observeOn(rx.Scheduler)
Found: io.reactivex.Scheduler!
Found
means the signature is io.reactivex.Scheduler AndroidSchedulers.mainThread()
This means that the Observable
is a RxJava 1 observable, while the RxAndroid version used is built for RxJava 2. Since you mentioned that the observable is provided by a library it means that library is built using RxJava 1.
You have 3 options to fix this:
Observable
to RxJava 2. (RxJavaInterop.toV2Observable(Observable);
)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With