Reputation: 171
I'm having a cast problem inside the subscribe method, i don't know why the new Observer is giving this issue.
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
Upvotes: 0
Views: 56
Reputation: 25573
Up until .subscribe(...)
it is an Observable
. However after subscribing it returns a Subscription
instance which can be used to cancel the subscription.
The exception occurs because you are casting this Subscription
back into an Observable
although they are completely unrelated.
Without knowing your intentions with that variable it is hard to say what the correct code would be.
Upvotes: 1