SingleObserver < ResponseBody > singleObserver = new SingleObserver < ResponseBody > () {
@Override
public void onSubscribe(@io.reactivex.rxjava3.annotations.NonNull Disposable d) {
Log.w("ABC", "S");
}
@Override
public void onSuccess(@io.reactivex.rxjava3.annotations.NonNull ResponseBody responseBody) {
try {
Log.w("ABC", responseBody.string());
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onError(@io.reactivex.rxjava3.annotations.NonNull Throwable e) {
Log.w("ABC", e.getMessage());
}
};
RetrofitInterface retrofitInterface = new Retrofit.Builder().baseUrl(Constants.BASE_URL).addCallAdapterFactory(RxJava3CallAdapterFactory.create()).build().create(RetrofitInterface.class);
retrofitInterface.getMainData(1).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(singleObserver); //The Error Here
I'm trying to use SingleObserver with the subscribe
method but I getting this error.
Error
Cannot resolve method 'subscribe(io.reactivex.rxjava3.core.SingleObserver<okhttp3.ResponseBody>)'
I fixed the problem: changed it from Observable< ResponseBody >
to Single< ResponseBody >
from interface.