关于RxJava2和retrofit2使用的问题
在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);
求解决办法~