react-native-navigation icon indicating copy to clipboard operation
react-native-navigation copied to clipboard

java.lang.ClassCastException when trying to push a new screen

Open giladno opened this issue 8 years ago • 17 comments

03-10 06:31:59.239 26571 26597 W Bundle  : Key timestamp expected Double but value was a java.lang.Integer.  The default value 0.0 was returned.
03-10 06:31:59.239 26571 26597 W Bundle  : Attempt to cast generated internal exception:
03-10 06:31:59.239 26571 26597 W Bundle  : java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double
03-10 06:31:59.239 26571 26597 W Bundle  : 	at android.os.BaseBundle.getDouble(BaseBundle.java:903)
03-10 06:31:59.239 26571 26597 W Bundle  : 	at android.os.BaseBundle.getDouble(BaseBundle.java:885)
03-10 06:31:59.239 26571 26597 W Bundle  : 	at com.reactnativenavigation.params.parsers.ScreenParamsParser.parse(ScreenParamsParser.java:32)
03-10 06:31:59.239 26571 26597 W Bundle  : 	at com.reactnativenavigation.controllers.NavigationCommandsHandler.push(NavigationCommandsHandler.java:40)
03-10 06:31:59.239 26571 26597 W Bundle  : 	at com.reactnativenavigation.bridge.NavigationReactModule.push(NavigationReactModule.java:182)
03-10 06:31:59.239 26571 26597 W Bundle  : 	at java.lang.reflect.Method.invoke(Native Method)
03-10 06:31:59.239 26571 26597 W Bundle  : 	at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:374)
03-10 06:31:59.239 26571 26597 W Bundle  : 	at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:162)
03-10 06:31:59.239 26571 26597 W Bundle  : 	at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
03-10 06:31:59.239 26571 26597 W Bundle  : 	at android.os.Handler.handleCallback(Handler.java:739)
03-10 06:31:59.239 26571 26597 W Bundle  : 	at android.os.Handler.dispatchMessage(Handler.java:95)
03-10 06:31:59.239 26571 26597 W Bundle  : 	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
03-10 06:31:59.239 26571 26597 W Bundle  : 	at android.os.Looper.loop(Looper.java:148)
03-10 06:31:59.239 26571 26597 W Bundle  : 	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
03-10 06:31:59.239 26571 26597 W Bundle  : 	at java.lang.Thread.run(Thread.java:818)

This exception shows in the console when trying to push a new screen (android device only, works well on emulator).

It tries to cast from Integer to Double, but it fails: https://github.com/wix/react-native-navigation/blob/e0a6ff2dad25c26eaa8ae1eacd3d2f185c5aebd5/android/app/src/main/java/com/reactnativenavigation/params/parsers/ScreenParamsParser.java#L32

Any suggestions?

giladno avatar Mar 10 '18 04:03 giladno

@giladno hmm not sure why this would happen, but you can PR a getNumber method which will gracefully try to get double and fallback to integer

guyca avatar Mar 11 '18 09:03 guyca

Actually ReadableMap of react native internally uses the HashMap where Key is String and value is Object to if you pass 1 it will take Integer and if you pass 1.0 it will take double so in that int a = 1; Integer b = 1; // unboxing requires Java 1.5+ double c = (double) a; // OK Double d = (Double) b; // No way. you can try Object obj=param.get(KEY_TIMESTAMP) if(obj instanceof Integer){ } if(object instanceof Double){ }

rahulpandey avatar Mar 13 '18 18:03 rahulpandey

+1, (even in android simulators)

leolusoli avatar Mar 22 '18 17:03 leolusoli

+1 (on android A5 2017)

congnguyen91 avatar Apr 13 '18 09:04 congnguyen91

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest version and report back. Thank you for your contributions.

stale[bot] avatar Jun 02 '18 03:06 stale[bot]

I'm having this issue on Android

humodev avatar Jun 04 '18 20:06 humodev

Same Here !! is that solution working @SudoPlz ? working with 1.44, I'm updating now to check if latests does the trick.

mojouy avatar Jun 04 '18 20:06 mojouy

I haven't thoroughly tested @mojouy but yeah it should work. I can confirm soon though.

SudoPlz avatar Jun 04 '18 20:06 SudoPlz

This is happening for me as well. Our app will successfully load but then will crash after a few seconds with the same error. Reproduceable on the emulator configuration attached, on version 1.1.458 (https://registry.yarnpkg.com/react-native-navigation/-/react-native-navigation-1.1.458.tgz#fe0ad5f7948768a82ebe69ed4bfc319c94ff9893)

screen shot 2018-06-15 at 2 28 11 pm

ChristianAyala avatar Jun 15 '18 19:06 ChristianAyala

I had a typo on my view breaking and causing this error. double check guys just in case.

mojouy avatar Jun 15 '18 19:06 mojouy

@mojouy Could you please elaborate what kind of typo you had?

maroun-baydoun avatar Jul 06 '18 03:07 maroun-baydoun

I'm having this issue on Android too. I was working with the remote debugger and had changed some of the code and wanted to reload the application. As soon as I double pressed R to reload, the app crashed with the same exception.

I'm using the following versions of react-native and RNN: "react-native": "0.56.0", "react-native-navigation": "^1.1.478",

usfngm avatar Aug 03 '18 18:08 usfngm

Having the same problem with those versions:

"react-native": "^0.56.0",
"react-native-navigation": "^1.1.479",

I do not understand what exactly is the proposed fix here. Could someone please elaborate?

zabojad avatar Aug 08 '18 14:08 zabojad

Having the same problem too. [email protected] react-native 0.56 Would also like some insight into what might be causing it. This is the code that triggers the error.

this.props.navigator.push({
            screen: "myApp.IdeaScreen",
            title: selGroup.name,
            passProps: {
                selectedKey: selGroup.key
            },
            animationType:'fade'
        });

spiro-stathakis avatar Aug 08 '18 20:08 spiro-stathakis

Yep, it's happening at every screen push...

zabojad avatar Aug 09 '18 13:08 zabojad

Seems to only be happening to me when running on a device. No issues in emulator.

patmisch avatar Aug 13 '18 20:08 patmisch

Also having this issue. Applying this patch solved it https://github.com/spritlesoftware/react-native-navigation/commit/d02bccf2642e77b27fd76ad385a7aee0c79d51ce

adamski avatar Nov 30 '18 12:11 adamski