错误:地图已被消耗-React Native

时间:2019-11-25 05:28:53

标签: android react-native react-native-android

基本上,我是通过响应本机并将信息从本机传递到js来连接本机android模块。

try {
    WritableMap params = new WritableNativeMap();
    params.putInt("connectionStatus", 2);
    sendEvent(mreactContext, "bleConnectionStatus", params);
    promise.resolve(params);
} catch (Exception exe) {
    Log.d(TAG, "Exception--: " + exe);
    promise.reject(exe);
}

显示异常

Exception--: com.facebook.react.bridge.ObjectAlreadyConsumedException: Map already consumed

注意:我已经回答了ObjectAlreadyConsumedException: Receiving map already consumed,但似乎是关于订购一行的。我按此顺序编写的代码仍然只显示异常。


更新

promise.resolve(params);中存在异常,因为当我删除并运行此行时,它不会显示任何异常。

1 个答案:

答案 0 :(得分:0)

使用

WritableArray mylist = Arguments.createArray();
try {
WritableMap params = Arguments.createMap();
params.putInt("connectionStatus", 2);
sendEvent(mreactContext, "bleConnectionStatus", params);
mylist.pushMap(params);
promise.resolve(mylist);
} catch (Exception exe) {
Log.d(TAG, "Exception--: " + exe);
promise.reject(exe);
}