Ich fange an, RxJava1 zu begreifen (jetzt lasst uns nicht verstehen, warum nicht RxJava2).Handhabung Überprüfte Ausnahme in RxJava
Ich habe Code wie unten:
MoviesAPI.findMovieURLsByType("comedy")
.map(s -> {
try {
return potentialCheckedException(s); //Throws CheckedException
} catch (MyExceptionType ex) {
return Exceptions.propagate(ex);
}
})
.subscribe(new Subscriber<String>() {
public void onCompleted() {
System.out.println("------Completed!-------");
}
public void onError(final Throwable e) {
System.out.println(e.getMessage());
}
public void onNext(final String s) {
System.out.println(s);
}
});
ich Fehler erhalten kompilieren wie unten:
Error:(28, 17) java: no suitable method found for subscribe(<anonymous rx.Subscriber<java.lang.String>>)
method rx.Observable.subscribe(rx.functions.Action1<? super java.io.Serializable>) is not applicable
(argument mismatch; <anonymous rx.Subscriber<java.lang.String>> cannot be converted to rx.functions.Action1<? super java.io.Serializable>)
method rx.Observable.subscribe(rx.Observer<? super java.io.Serializable>) is not applicable
(argument mismatch; <anonymous rx.Subscriber<java.lang.String>> cannot be converted to rx.Observer<? super java.io.Serializable>)
method rx.Observable.subscribe(rx.Subscriber<? super java.io.Serializable>) is not applicable
(argument mismatch; <anonymous rx.Subscriber<java.lang.String>> cannot be converted to rx.Subscriber<? super java.io.Serializable>)
method rx.Observable.<T>subscribe(rx.Subscriber<? super T>,rx.Observable<T>) is not applicable
(cannot infer type-variable(s) T
(actual and formal argument lists differ in length))
Wenn ich den Try-Catch-Block entfernen waren und ersetzen potentialCheckedException(s)
mit noPotentialCheckedException(s)
sagen, dann Der Kompilierfehler verschwindet. Warum? Was fehlt mir? Wickelt CheckedException
mit Exceptions.propagate(ex)
nicht genug?
Vielen Dank im Voraus.
Dumm ich. Danke @akarnokd. Ich habe mich gefragt, was ich in RxJava vermisse, wenn es tatsächlich auf die Grundlagen von Java hinausläuft. – karthiks