/ /サブスクリプションのThrowable onErrorコンポーネントが期待どおりにコンパイルされない-java、rx-android、throwable、rxandroidble

サブスクリプションのThrowable onErrorコンポーネントが正しくコンパイルされない

Observableを使用してRxAndroidBle接続ステータスの監視を設定しようとしています。以下のコードはコンパイルされます(まだ「テストできません」)が、その理由は完全にはわかりません。の2番目のパラメーター subscribe コールは Action1<java.lang.Throwable> onError。これを正しく実装しましたか?なぜ書けないの

throwable -> throw throwable

試してみると、2番目の「throwable」には「シンボル「throwable」を解決できません」というフラグが立てられ、「->」と「throw」の間では、右括弧、左中括弧、またはセミコロンが期待されます。

// set up monitoring of connection state with a subscription
boolean setConnectionStateNotification() {
asBleDevice.observeConnectionStateChanges()
.subscribe(
connectionState -> asBleConnectionState = connectionState,
throwable -> new RuntimeException( "Problem with subscription to Connection State Changes: "
+ throwable.getMessage() )
);
return true;
}

TBH私は、「 Action1<Throwable>;誰か説明してもらえますか?

更新:私はそれを理解したかもしれないと思う。そのようです:

 boolean setConnectionStateNotification() {
asBleDevice.observeConnectionStateChanges() // returns Observable<RxBleConnection.RxBleConnectionState>
.subscribe(
connectionState -> asBleConnectionState = connectionState,
throwable -> { throw new RuntimeException(
"Problem with subscription to Connection State Changes: "
+ throwable.getMessage(), throwable );
},
( ) -> RxBleLog.d( "Connection State Observable has completed", null ) // onCompleted() with no arguments
); // subscribe
return true;
}

(onCompleted()呼び出し用の3番目のオプションハンドラーも追加しました。)

回答:

回答№1は0

これは正しいと思う:

boolean setConnectionStateNotification() {
asBleDevice.observeConnectionStateChanges() // returns Observable<RxBleConnection.RxBleConnectionState>
.subscribe(
connectionState -> asBleConnectionState = connectionState, // save value
throwable -> { throw new RuntimeException(
"Problem with subscription to Connection State Changes: "
+ throwable.getMessage(), throwable );
},
( ) -> RxBleLog.d( "Connection State Observable has completed", null ) // onCompleted() with no arguments
); // subscribe
return true;
}