简体   繁体   English

RxAndroid问题与改造?

[英]RxAndroid issue with retrofit?

I'm having a cast problem inside the subscribe method, i don't know why the new Observer is giving this issue. 我在subscription方法中遇到强制转换问题,我不知道为什么新的Observer会出现此问题。

 Observable<GradeModel> getGrade = retrofit
                .create(GradeService.class)
                .getGrade()
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .map(model -> {
                    // transform model
                    DecimalFormat grades = (DecimalFormat) model.getGrades();
                    return grades;
                })
                .subscribe(new Subscriber<DecimalFormat>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.i(TAG, "onError method of observer");
                    }

                    @Override
                    public void onNext(DecimalFormat grades) {
                        mainPresenter.setListGrades(grades);
                    }
                });

Required: rx.Observable Found: rx.Subscription 必需:rx.Observable找到:rx.Subscription

Up until .subscribe(...) it is an Observable . 直到.subscribe(...)为止都是Observable However after subscribing it returns a Subscription instance which can be used to cancel the subscription. 但是,在订阅后,它返回一个Subscription实例,该实例可用于取消订阅。

The exception occurs because you are casting this Subscription back into an Observable although they are completely unrelated. 发生异常是因为您将此Subscription强制转换回Observable尽管它们是完全无关的。

Without knowing your intentions with that variable it is hard to say what the correct code would be. 如果不知道您对该变量的意图,那么很难说出正确的代码是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM