观察者对象上的订阅(新订阅者<XXX>()...)不起作用 Retrofit-RxJava

subscribe(new Subscriber<XXX>() ...) on Observer object is not working Retrofit-RxJava

我正在按照本教程 https://youtu.be/YoSr5mi5kKU?t=30m52s 学习 Android 中的 RxJava 和 MVP 模式。

但是当它到达观察对象的时刻时,这现在起作用了:

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) {

            }
        });
}

错误是:无法解析方法'subscribe(anonymous rx.Subscriber)'

服务接口是这样的:

public interface ServiceTMDB {
    @GET("movie/popular")
    Observable<ResponseTMDB> getDataTMBDService(@QueryMap Map<String, String> params);
}

我不知道我到底错过了什么或做错了什么。

Gradle 进口:

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'

简单的问题,你正在添加

compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'

与 RxJava 一起工作 1.x


但是对于

compile 'io.reactivex.rxjava2:rxjava:2.0.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'

你应该添加

compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'

您正在添加:

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'