我是React Native的新手。在开发本地模块时,遇到了回调的问题。 以下是React Native的错误消息:
02-05 17:43:26.387 32301-32570/com.awesomeproject2 E/ReactNativeJNI: Got JS Exception: Exception calling object as function: abc,function f1() {
_ToastExample2.default.show('1111', _ToastExample2.default.SHORT);
},72,73 is not usable as a native method argument (<unknown file>:1845)
02-05 17:43:26.387 32301-32570/com.awesomeproject2 E/ReactNativeJNI: Got JS Stack: invariant@http://localhost:8081/index.delta?platform=android&dev=true&minify=false:1838:26
enqueueNativeCall@http://localhost:8081/index.delta?platform=android&dev=true&minify=false:2259:20
fn@http://localhost:8081/index.delta?platform=android&dev=true&minify=false:1999:40
onBtnPress@http://localhost:8081/index.delta?platform=android&dev=true&minify=false:58362:32
proxiedMethod@http://localhost:8081/index.delta?platform=android&dev=true&minify=false:34324:37
proxiedMethod@[native code]
touchableHandlePress@http://localhost:8081/index.delta?platform=android&dev=true&minify=false:37170:47
touchableHandlePress@[native code]
_performSideEffectsForTransition@http://localhost:8081/index.delta?platform=android&dev=true&minify=false:36821:36
_performSideEffectsForTransition@[native code]
_receiveSignal@http://localhost:8081/index.delta?platform=android&dev=true&minify=false:36754:46
_receiveSignal@[native code]
touchableHandleResponderRelease@http://localhost:8081/index.delta?platform=android&dev=true&
02-05 17:43:26.393 32301-32570/com.awesomeproject2 E/unknown:ReactNative: Exception in native call
java.lang.RuntimeException: Error calling RCTEventEmitter.receiveTouches
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
at android.os.Looper.loop(Looper.java:135)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
at java.lang.Thread.run(Thread.java:818)
Caused by: com.facebook.jni.CppException: Exception calling object as function: abc,function f1() {
_ToastExample2.default.show('1111', _ToastExample2.default.SHORT);
},72,73 is not usable as a native method argument (<unknown file>:1845)
... 7 more
我的本地模块看起来是这样的
@ReactMethod
public void testCallback(String message, Callback c1, Callback c2, Callback c3) {
if (message.equals("123")) {
c1.invoke(message);
} else if (message.equals("abc")) {
c2.invoke(message);
} else {
c3.invoke(message);
}
}
而我的 React 中的调用函数
onBtnPress() {
function f1 () {
ToastExample.show('1111', ToastExample.SHORT);
};
function f2 () {
ToastExample.show('2222', ToastExample.SHORT);
};
function f3 () {
ToastExample.show('3333', ToastExample.SHORT);
};
ToastExample.testCallback('abc', f1, f2, f3);
}
我不知道为什么会出现这个错误,有人可以帮帮我吗?谢谢。