Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot resolve method 'subscribeon(io.reactivex.scheduler)'

I'm tring to use rxjava with retrofit in android studio, but when I add observable in compositedisposable, I get this error:

cannot resolve method 'subscribeon(io.reactivex.scheduler)'

In fact, I am using this sample code

       @POST("/auth/register")
       Observable<Response>register(@Body User user);

Code

 private CompositeDisposable comdisposables= new CompositeDisposable();
 LoginRetrofitInterface requestInterface = new Retrofit.Builder()
    .baseUrl(Constants.BASE_URL)
    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
    .addConverterFactory(GsonConverterFactory.create())
    .build().create(LoginRetrofitInterface.class);

     comdisposables.add(requestInterface.register(user)
    .observeOn(AndroidSchedulers.mainThread())
    .subscribeOn(Schedulers.io())
    .subscribe(this::handleResponse,this::handleError));

and dependencies

implementation 'com.google.code.gson:gson:2.6.1'

 implementation 'com.squareup.retrofit2:retrofit:2.5.0'

 implementation 'com.squareup.retrofit2:converter-gson:2.5.0'

//implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:2.1.0'

// com.jakewharton.retrofit:retrofit2-rxjava2-adapter:2.2.0

 implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'

 // RxJava

 implementation 'io.reactivex.rxjava2:rxjava:2.2.8'

 implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
like image 836
Sam Avatar asked Feb 27 '26 21:02

Sam


1 Answers

tnx to @EpicPandaForce for his/her helpful comments , error :cannot resolve method 'subscribeon(io.reactivex.scheduler)' solved.

android.database.Observable was imported instead of io.reactivex.Observable.

like image 176
Sam Avatar answered Mar 01 '26 09:03

Sam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!