错误及分析
异常如下:
java.lang.IllegalArgumentException: Unable to create call adapter for io.reactivex.Observable<me.fallblank.weiworld.bean.ContentResponse>
for method IWeiboContent.listLastWeibo
at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:751)
at retrofit2.ServiceMethod$Builder.createCallAdapter(ServiceMethod.java:236)
at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:161)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:169)
at retrofit2.Retrofit$1.invoke(Retrofit.java:146)
at com.sun.proxy.$Proxy5.listLastWeibo(Unknown Source)
...
问题原因:<br />
retrofit没有默认提供给RxJava 2.x.y的适配器,无法把call转换为相应的Observable,但这在RxJava1中却是可以的。出现这个错误是升级了Rxjava却没有配置retrofit的adapter导致。<br />
修正
引入相应依赖:
compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
//也可以用Jackwharton写的adapter
添加adapter到retrofit:
Retrofit mRetrofit = new Retrofit.Builder()
...
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
...
.build();
至此,问题修复!