Caused by: java.lang.IllegalArgumentException: Could not locate call adapter for rx.Observable<>错误
2016-08-17 13:52
519 查看
public class TRService { public static final String BASE_TRC_URL = "http://www.tuling123.com/openapi/"; private static Retrofit retrofit = new Retrofit.Builder() .baseUrl(BASE_TRC_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); private TRService() { } public static TRApi createTRService() { return retrofit.create(TRApi.class); } }
public interface TRApi {
/**
* 可以看到这里应该是post传递的参数。
* @param key
* @param info
* @param userid
* @return
*/
@FormUrlEncoded
@POST("api")
Observable<TREntity> getTRResponse(@Field("key") String key, @Field("info") String info, @Field("userid") String userid);
}
调用的地方:
private void gainChat(String str) {
service.getTRResponse(Contant.TRC_KEY, str, Contant.TRC_USER_ID)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<TREntity>() {
@Override
public void call(TREntity trEntity) {
if (trEntity != null) {
String str;
if (trEntity.getCode() == 40004) {
str = Contant.TRC_ROBOT_REST;
} else {
str = trEntity.getText();
}
addData(new ChatBean(TRClientAdapter.TYPE_ROBOT, str));
}
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
addData(new ChatBean(TRClientAdapter.TYPE_ROBOT, Contant.TRC_ROBOT_FAILED));
}
});
}
出现如下错误:
Caused by: java.lang.IllegalArgumentException: Could not locate call adapter for rx.Observable<>
要在构建Retrofit时指定适配器模式为RxJavaCallAdapterFactory,修改如下:
public class TRService {
public static final String BASE_TRC_URL = "http://www.tuling123.com/openapi/";
private static Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_TRC_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
private TRService() {
}
public static TRApi createTRService() {
return retrofit.create(TRApi.class);
}
}
如果没有使用RxJavaCallAdapterFractory,那么使用Retrofit的回调,如下:
public interface TRApi {
/**
* 可以看到这里应该是post传递的参数。
* @param key
* @param info
* @param userid
* @return
*/
@FormUrlEncoded
@POST("api")
Call<TREntity> getTRResponse(@Field("key") String key, @Field("info") String info, @Field("userid") String userid);
}
相关文章推荐
- 解决kylin报错:Failed to create dictionary on <db>.<table>, Caused by: java.lang.IllegalArgumentException: Too high cardinality is not suitable for dictionary
- Caused by: java.lang.IllegalArgumentException: Argument for @NotNull paramet
- Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'redis.maxWaitMillis' i
- Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for …
- 关于spring java.lang.IllegalArgumentException: Name for argument type [java.lang.String] 的错误
- java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for...
- MyBatis异常java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for
- Android Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
- 关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析
- 关于错误信息:java.lang.IllegalArgumentException: Document base XXXX does not exist or 的记录
- struts2下载文件错误信息java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name
- Caused by: java.lang.IllegalArgumentException: addChild: Child name 'localhost' is not unique
- java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for
- Caused by: java.lang.IllegalArgumentException: Original must not be null
- Android Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
- 错误:java.lang.illegalArgumentException:No view id found for fragment
- 【Caused by: java.lang.IllegalArgumentException: Original must not be null 】
- Android Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
- java.lang.IllegalArgumentException:Document base ……does not exist or is not a readable directory错误的解决方案
- java.lang.IllegalArgumentException: <session-config> element is limited to 1 occurrence 分类: Tomcat 2014-12-09 11:20 513人阅读 评论(0) 收藏