Java 订阅的可丢弃onError组件未按预期编译

Java 订阅的可丢弃onError组件未按预期编译,java,rx-android,throwable,rxandroidble,Java,Rx Android,Throwable,Rxandroidble,尝试使用可观察的设置Rxandroid连接状态的监视。下面的代码可以编译(我还无法测试),但我不完全理解为什么。subscribe调用的第二个参数应该是Action1 onError。我是否正确地实现了这一点?为什么我不能写呢 throwable -> throw throwable 当我尝试时,第二个“throwable”标记为“无法解析符号‘throwable’”,在“->”和“throw”之间,它表示需要右括号、左大括号或分号 // set up monitoring of con

尝试使用可观察的设置Rxandroid连接状态的监视。下面的代码可以编译(我还无法测试),但我不完全理解为什么。
subscribe
调用的第二个参数应该是
Action1 onError
。我是否正确地实现了这一点?为什么我不能写呢

throwable -> throw throwable
当我尝试时,第二个“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我在思考
操作1
的概念时遇到了困难;有人能解释一下吗

更新:我想我可能已经弄明白了。像这样:

 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;
}
boolean setConnectionStateNotification(){
asBleDevice.observeConnectionStateChanges()//返回可观察的
.订阅(
connectionState->asBleConnectionState=connectionState,
throwable->{抛出新运行时异常(
“订阅连接状态更改时出现问题:”
+throwable.getMessage(),throwable);
},
()->RxBleLog.d(“可观察的连接状态已完成”,null)//onCompleted(),不带参数
);//订阅
返回true;
}

(我还为onCompleted()调用添加了第三个可选处理程序。)

我认为这可能是正确的:

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;
}
boolean setConnectionStateNotification(){
asBleDevice.observeConnectionStateChanges()//返回可观察的
.订阅(
connectionState->asBleConnectionState=connectionState,//保存值
throwable->{抛出新运行时异常(
“订阅连接状态更改时出现问题:”
+throwable.getMessage(),throwable);
},
()->RxBleLog.d(“可观察的连接状态已完成”,null)//onCompleted(),不带参数
);//订阅
返回true;
}

你好。你能描述一下你到底想要实现什么吗?