Hi Niklas,
This is nice blog explaining about CompositeDisposable(). I have implemented a Code as below.
private CompositeDisposable mDisposable;
mDisposable = new CompositeDisposable();
mDisposable.add(mViewModel.getData(“GetMatchDetails”,createJsonObject())
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::setData,this::handleError));private void setData(JSONObject jsonObject){
textView = (TextView)findViewById(R.id.textView);
textView.setText(jsonObject.toString());
}private void handleError(Throwable e){
Log.d(“error”,e.getMessage());}
The code is working fine with .subscribe(this::setData), but when I put .subscribe(this::setData, this::handleError) got the error. what would be reason for it?
W/System.err: io.reactivex.exceptions.UndeliverableException: java.lang.IncompatibleClassChangeError: Class ‘example.com.mvvmrxjava2.-$Lambda$0’ does not implement interface ‘io.reactivex.functions.Function’ in call to ‘java.lang.Object io.reactivex.functions.Function.apply(java.lang.Object)’ (declaration of ‘io.reactivex.internal.operators.observable.ObservableMap$MapObserver’ appears in /data/app/example.com.mvvmrxjava2–1/base.apk)
W/System.err: at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:349)
W/System.err: at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:64)
W/System.err: at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
W/System.err: at java.lang.Thread.run(Thread.java:818)
W/System.err: Caused by: java.lang.IncompatibleClassChangeError: Class ‘example.com.mvvmrxjava2.-$Lambda$0’ does not implement interface ‘io.reactivex.functions.Function’ in call to ‘java.lang.Object io.reactivex.functions.Function.apply(java.lang.Object)’ (declaration of ‘io.reactivex.internal.operators.observable.ObservableMap$MapObserver’ appears in /data/app/example.com.mvvmrxjava2–1/base.apk)
W/System.err: at io.reactivex.internal.operators.observable.ObservableMap$MapObserver.onNext(ObservableMap.java:59)
W/System.err: at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:200)
W/System.err: at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:252)
W/System.err: at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
Thanks in advance.