错误显示:无法为 io.reactivex.Observable<POJO> 创建调用适配器
Error showing : Unable to create call adapter for io.reactivex.Observable<POJO>
我正在使用带有 rxjava2 的 retrofit2。
我在 gradle 中主要使用了最新的库,并且尝试了很多创建适配器的方法。
我还创建了一些自定义适配器,但似乎无法使用它
服务:
public static Retrofit getClient() {
if (retrofit==null) {
retrofit = new Retrofit.Builder().baseUrl(AppConstants.BASE_URL)
.addConverterFactory(GsonConverterFactory.create()).
addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build();
}
return retrofit;
}
fragment code:
ApiInterface apiInterface
=ApiClient.getClient().create(ApiInterface.class);
apiInterface.getCategoryVideos(AppConstants.API_KEY)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(new Observer<Video>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Video value) {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
我试过很多适配器,但没有一个适配器工作。我是
日志输出是:
如有任何建议或解决方案,我们将不胜感激。
我也尝试过这个 link
中的解决方案
尝试更改创建客户端
public class MyClient {
private static MyClient instance;
private ApiInterface apiInterface;
private MyClient() {
final Retrofit retrofit = new Retrofit.Builder().baseUrl(AppConstants.BASE_URL)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
gitHubService = retrofit.create(ApiInterface.class);
}
public static MyClient getInstance() {
if (instance == null) {
instance = new MyClient();
}
return instance;
}
}
和片段代码
private Subscription subscription;
...
subscription = MyClient.getInstance().getCategoryVideos(AppConstants.API_KEY)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Video>() {
@Override public void onCompleted() {
Log.d(TAG, "In onCompleted()");
}
@Override public void onError(Throwable e) {
e.printStackTrace();
Log.d(TAG, "In onError()");
}
@Override public void onNext(Video value) {
Log.d(TAG, "In onNext()");
}
});
我正在使用带有 rxjava2 的 retrofit2。
我在 gradle 中主要使用了最新的库,并且尝试了很多创建适配器的方法。
我还创建了一些自定义适配器,但似乎无法使用它
服务:
public static Retrofit getClient() {
if (retrofit==null) {
retrofit = new Retrofit.Builder().baseUrl(AppConstants.BASE_URL)
.addConverterFactory(GsonConverterFactory.create()).
addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build();
}
return retrofit;
}
fragment code:
ApiInterface apiInterface
=ApiClient.getClient().create(ApiInterface.class);
apiInterface.getCategoryVideos(AppConstants.API_KEY)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(new Observer<Video>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Video value) {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
我试过很多适配器,但没有一个适配器工作。我是
日志输出是:
如有任何建议或解决方案,我们将不胜感激。
我也尝试过这个 link
尝试更改创建客户端
public class MyClient {
private static MyClient instance;
private ApiInterface apiInterface;
private MyClient() {
final Retrofit retrofit = new Retrofit.Builder().baseUrl(AppConstants.BASE_URL)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
gitHubService = retrofit.create(ApiInterface.class);
}
public static MyClient getInstance() {
if (instance == null) {
instance = new MyClient();
}
return instance;
}
}
和片段代码
private Subscription subscription;
...
subscription = MyClient.getInstance().getCategoryVideos(AppConstants.API_KEY)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Video>() {
@Override public void onCompleted() {
Log.d(TAG, "In onCompleted()");
}
@Override public void onError(Throwable e) {
e.printStackTrace();
Log.d(TAG, "In onError()");
}
@Override public void onNext(Video value) {
Log.d(TAG, "In onNext()");
}
});