活动中:
Double price = o.getDouble ( "totalprice" );
Observable<Double> floatObservable = Observable.just(price);
MathObservable
.sumDouble(floatObservable)
.subscribe(new Observer<Integer>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Integer integer) {
System.out.println("Sum: " + integer);
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
等级:
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex:rxjava-math:1.0.0'
错误发生在第
行:.sumDouble(floatObservable)
错误:
无法解析方法 'sumDouble(io.reactivex.Observable)'
答案 0 :(得分:2)
在您的app.gradle中添加依赖项
implementation "com.github.akarnokd:rxjava2-extensions:0.20.8"
然后
Observable<Double> floatObservable = Observable.just(1.2,1.3);
MathObservable
.sumDouble(floatObservable)
.subscribe(new Observer<Double>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Double aDouble) {
System.out.println("Sum: " + aDouble);
//if you want int convert here
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
它可以正常工作..answer为2.5