admin管理员组文章数量:1291045
We have a react-native app (with expo, but not expo-go), where under certain conditions, the following exception appears and the app crashes.
I know, at some point we are passing a String
where React-Native expects a Double
. I really would like to know where. I tried with debugging the app-debug.apk
. But when adding a breakpoint at the method in ReadableNativeArray
, the App just hangs and the screen of my device stays black.
Is there any way to find out which value caused this exception? Or which code is responsible for this?
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Double
at com.facebook.react.bridge.ReadableNativeArray.getDouble(ReadableNativeArray.java:92)
at com.facebook.react.bridge.JavaMethodWrapper$4.extractArgument(JavaMethodWrapper.java:64)
at com.facebook.react.bridge.JavaMethodWrapper$4.extractArgument(JavaMethodWrapper.java:60)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:356)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:146)
at com.facebook.jni.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:223)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl.lambda$startNewBackgroundThread$2(MessageQueueThreadImpl.java:217)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$$ExternalSyntheticLambda1.run(D8$$SyntheticClass:0)
at java.lang.Thread.run(Thread.java:923)
We have a react-native app (with expo, but not expo-go), where under certain conditions, the following exception appears and the app crashes.
I know, at some point we are passing a String
where React-Native expects a Double
. I really would like to know where. I tried with debugging the app-debug.apk
. But when adding a breakpoint at the method in ReadableNativeArray
, the App just hangs and the screen of my device stays black.
Is there any way to find out which value caused this exception? Or which code is responsible for this?
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Double
at com.facebook.react.bridge.ReadableNativeArray.getDouble(ReadableNativeArray.java:92)
at com.facebook.react.bridge.JavaMethodWrapper$4.extractArgument(JavaMethodWrapper.java:64)
at com.facebook.react.bridge.JavaMethodWrapper$4.extractArgument(JavaMethodWrapper.java:60)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:356)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:146)
at com.facebook.jni.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:223)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl.lambda$startNewBackgroundThread$2(MessageQueueThreadImpl.java:217)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$$ExternalSyntheticLambda1.run(D8$$SyntheticClass:0)
at java.lang.Thread.run(Thread.java:923)
Share
Improve this question
asked Feb 13 at 15:08
Paul Wellner BouPaul Wellner Bou
5545 silver badges18 bronze badges
1 Answer
Reset to default 0I found a solution:
- Patch
./node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReadableNativeArray.java
adding more information to the exception:
@Override
public double getDouble(int index) {
Object value = getLocalArray()[index];
try {
return ((Double) getLocalArray()[index]).doubleValue();
} catch (ClassCastException e) {
throw new ClassCastException(
"Value at index " + index + " is not a number: " + value
);
}
}
- Configure your android buildscript to compile React Native from source instead of using prebuilt
aar
files (see https://reactnative.dev/contributing/how-to-build-from-source), adding:
includeBuild('../node_modules/react-native') {
dependencySubstitution {
substitute(module("com.facebook.react:react-android")).using(project(":packages:react-native:ReactAndroid"))
substitute(module("com.facebook.react:react-native")).using(project(":packages:react-native:ReactAndroid"))
substitute(module("com.facebook.react:hermes-android")).using(project(":packages:react-native:ReactAndroid:hermes-engine"))
substitute(module("com.facebook.react:hermes-engine")).using(project(":packages:react-native:ReactAndroid:hermes-engine"))
}
}
- Build app and run
本文标签:
版权声明:本文标题:How to debug and find the cause of "ClassCastException: java.lang.String cannot be cast to java.lang.Double" i 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741521888a2383237.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论