LCRapidDevelop icon indicating copy to clipboard operation
LCRapidDevelop copied to clipboard

请教下楼主

Open SomnusWu opened this issue 9 years ago • 4 comments

楼主大大 我用的是RxJava2.0 RxAndroid2 .0

compile 'io.reactivex.rxjava2:rxandroid:2.0.0' compile 'io.reactivex.rxjava2:rxjava:2.0.0'

BookListModel.java改为

 public void LoadData(String type, int pageIndex, final OnLoadDataListListener listener) {
        HttpRequest.getInstance().HttpDataToSchoolList(type, pageIndex, new Observer<List<BookListDto>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(List<BookListDto> value) {
                listener.onSuccess(value);
            }

            @Override
            public void onError(Throwable e) {
                //设置页面为加载错误
                listener.onFailure(e);
            }

            @Override
            public void onComplete() {

            }
        });
    }
//请求列表数据
    public void HttpDataToSchoolList(String type, int pageIndex, Observer<List<BookListDto>> observer) {
        Observable observable = service.getBookList(type, pageIndex).map(new HttpResultFunc<List<BookListDto>>());
        setSubscribe(observable, observer);
    }

然后把Fun1改为了

 private class HttpResultFunc<T> implements Function<HttpResultBase<T>, T> {
        @Override
        public T apply(HttpResultBase<T> tHttpResultBase) throws Exception {
            if (tHttpResultBase.getCode() != 1) {
                throw new ApiException(tHttpResultBase);
            }
            return tHttpResultBase.getData();
        }
    }

就报了如下错误: Caused by: java.lang.IllegalArgumentException: Unable to create call adapter for io.reactivex.Observable<com.somnus.androidhttpdemo.ui.entity.HttpResultBase<java.util.List<com.somnus.androidhttpdemo.ui.entity.BookListDto>>> for method HttpServiceApi.getBookList

问下大大该怎么修改啊 。ths

SomnusWu avatar Nov 07 '16 06:11 SomnusWu

Add this to your app gradle : compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'

Update your retrofit builder :

Retrofit retrofit = new Retrofit.Builder()
    .baseUrl("https://api.example.com")
    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
    .build();

alouanemed avatar Dec 06 '16 19:12 alouanemed

thanks

SomnusWu avatar Dec 07 '16 01:12 SomnusWu

@alouanemed but , Still not running . url : https://github.com/SomnusWu/AndroidHttpDemo.git

SomnusWu avatar Dec 07 '16 03:12 SomnusWu

Update this :

https://github.com/SomnusWu/AndroidHttpDemo/blob/master/app/src/main/java/com/somnus/androidhttpdemo/http/retrofit/RetrofitUtils.java#L38

With this :

.addCallAdapterFactory(RxJava2CallAdapterFactory.create())

alouanemed avatar Dec 08 '16 11:12 alouanemed