I'm trying to fetch API with RxJava by following this tutorial: https://www.youtube.com/watch?v=VObSnk5jrpc&list=PLRRNzqzbPLd906bPH-xFz9Oy2IcjqVWCH&index=6
But I got an error saying:
Type mismatch. Required: io.reactivex.disposables.Disposable! Found: io.reactivex.rxjava3.disposables.Disposable!
Here is the code:
try{
compositeDisposable.add(
apiService.getMovieDetails(movieId)
.subscribeOn(Schedulers.io())
.subscribe(
{
_downloadedMovieDetailsResponse.postValue(it)
_networkState.postValue(NetworkState.LOADED)
},
{
_networkState.postValue(NetworkState.ERROR)
Log.e("MovieDetailsDataSource", it.message!!) //this is where the error is (the it.message)
}
)
)
}
catch (e: Exception){
Log.e("MovieDetailsDataSource",e.message!!) //this is where the error is (the e.message)
}
I tried compositeDisposable.add with capital C, but then it says that I should import something and when I want to import it, it doesn't import it and still show the import error
I don't understand what is the problem.
should I use an old version of RXjava?
is some part of this code deprecated in these new versions of RXjava?
CodePudding user response:
Yes. You have to add a couple of Rxjava libraries for io.reactivex.disposables.Disposable.
implementation 'io.reactivex.rxjava2:rxjava:2.2.19'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
Then create the object of CompositeDisposable and use it.
val compositeDisposable = CompositeDisposable()
CodePudding user response:
oh. finally I solved my problem now. it was about importing the wrong line. I deleted the old one from top of the page and replaced it with : import io.reactivex.rxjava3.disposables.CompositeDisposable and everything got ok.