在retrofit2配合使用rxjava时候,出现了如下问题:
java.lang.IllegalArgumentException: Unable to create call adapter for io.reactivex.Observable<com.price.take_new.Example> for method NewsService.getUser依赖:
compile 'io.reactivex.rxjava2:rxjava:2.0.4'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.squareup.okhttp3:okhttp:3.5.0'
compile 'com.google.code.gson:gson:2.8.0' compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'这是我的代码:
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl("http://takeapp.com.cn/Home/register/")
.build();
NewsService api = retrofit.create(NewsService .class);
api.getUser("13222222222",MD5Tool.md5("123")).subscribeOn(Schedulers.io()).
observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<Example>() {
@Override
public void accept(Example example) throws Exception {
Log.e(TAG,"TEST");
}
});接口代码:
Observable<Example> getUser(@Field("phone_num") String username,@Field("password") String password);求解决办法~
java.lang.IllegalArgumentException: Unable to create call adapter for io.reactivex.Observable<com.price.take_new.Example> for method NewsService.getUser依赖:
compile 'io.reactivex.rxjava2:rxjava:2.0.4'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.squareup.okhttp3:okhttp:3.5.0'
compile 'com.google.code.gson:gson:2.8.0' compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'这是我的代码:
Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl("http://takeapp.com.cn/Home/register/")
.build();
NewsService api = retrofit.create(NewsService .class);
api.getUser("13222222222",MD5Tool.md5("123")).subscribeOn(Schedulers.io()).
observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<Example>() {
@Override
public void accept(Example example) throws Exception {
Log.e(TAG,"TEST");
}
});接口代码:
Observable<Example> getUser(@Field("phone_num") String username,@Field("password") String password);求解决办法~
@FormUrlEncoded
@POST("user-login/login")
Observable<LoginModel> loginData(@Field("username") String username, @Field("password") String password);
应该是少了这两个注解
@FormUrlEncoded
@POST("user-login/login")
Observable<LoginModel> loginData(@Field("username") String username, @Field("password") String password);
应该是少了这两个注解
已经加上了,并不行
@FormUrlEncoded
@POST("user-login/login")
Observable<LoginModel> loginData(@Field("username") String username, @Field("password") String password);
应该是少了这两个注解
已经加上了,并不行
那应该就是你的写法有问题,建议再去看看别人怎么写的
@FormUrlEncoded
@POST("user-login/login")
Observable<LoginModel> loginData(@Field("username") String username, @Field("password") String password);
应该是少了这两个注解
已经加上了,并不行
那应该就是你的写法有问题,建议再去看看别人怎么写的
我想说我就是按照别人的教程一步步写的,但还是谢谢你
@FormUrlEncoded
@POST("user-login/login")
Observable<LoginModel> loginData(@Field("username") String username, @Field("password") String password);
应该是少了这两个注解
已经加上了,并不行
那应该就是你的写法有问题,建议再去看看别人怎么写的
我想说我就是按照别人的教程一步步写的,但还是谢谢你
问题解决了吗?你把教程地址贴一下,我去瞅瞅
但是retrofit2一开始是基于rxjava开发的适配器即adapter-rxjava,这个适配器只适合rxjava
如果想使用rxjava2就得使用adapter-rxjava2适配器
这个适配器有两个,一个是retrofit2官方设计的(上线不久),另外一个就是jakewharton大神弄出来的retrofit2-rxjava2-adapter适配器
你使用了 rxjava2, compile 'io.reactivex.rxjava2:rxjava:2.0.4'
但是retrofit2一开始是基于rxjava开发的适配器即adapter-rxjava,这个适配器只适合rxjava
如果想使用rxjava2就得使用adapter-rxjava2适配器
这个适配器有两个,一个是retrofit2官方设计的(上线不久),另外一个就是jakewharton大神弄出来的retrofit2-rxjava2-adapter适配器
你使用了 rxjava2, compile 'io.reactivex.rxjava2:rxjava:2.0.4'
但是retrofit2一开始是基于rxjava开发的适配器即adapter-rxjava,这个适配器只适合rxjava
如果想使用rxjava2就得使用adapter-rxjava2适配器
这个适配器有两个,一个是retrofit2官方设计的(上线不久),另外一个就是jakewharton大神弄出来的retrofit2-rxjava2-adapter适配器
我找到了这个retrofit2-rxjava2-adapter,这是正解。