Reputation: 7936
I'm following this tutorial https://youtu.be/YoSr5mi5kKU?t=30m52s to learn a bit on RxJava and MVP pattern in Android.
But when it arrives the momento to observe the object this now works:
public void getDataTMDBinteractor() {
Map<String, String> params = new HashMap<>();
params.put("api_key", "zzzzzzzzzzzzzzzzzzzzzzzzzzz");
Observable<ResponseTMDB> responseTMDBObservable = serviceTMDB.getDataTMBDService(params);
responseTMDBObservable.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<ResponseTMDB>() { //Starting error from here
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(ResponseTMDB responseTMDB) {
}
});
}
The error is: Cannot resolve method 'subscribe(anonymous rx.Subscriber)'
And the Service Interface is like this:
public interface ServiceTMDB {
@GET("movie/popular")
Observable<ResponseTMDB> getDataTMBDService(@QueryMap Map<String, String> params);
}
I don't know what exactly I'm missing or doing bad.
Gradle imports:
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'io.reactivex.rxjava2:rxjava:2.0.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.google.code.gson:gson:2.8.0'
Upvotes: 1
Views: 2412
Reputation: 1
You are adding:
compile 'io.reactivex:rxandroid:1.2.1'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
Upvotes: 0
Reputation: 81539
Simple problem, you are adding
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
which works with RxJava 1.x
But for
compile 'io.reactivex.rxjava2:rxjava:2.0.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
you should be adding
compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
Upvotes: 2