Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: android.view.ViewParent android.view.View.getParent()' on a null object reference #646

Closed
melkayam92 opened this issue Sep 20, 2020 · 13 comments · Fixed by #671
Closed
Labels
Missing repro This issue need minimum repro scenario Platform: Android This issue is specific to Android

Comments

@melkayam92
Copy link

Hi,

Since I upgraded from 2.5.0 to 2.10.* I'm getting a lot crashes in production saying:

"android.view.ViewParent android.view.View.getParent()' on a null object reference" - NullPointerExecption
"FragmentManager has been destroyed" - IllegalStateException

"@react-navigation/native": "^5.7.3",
"@react-navigation/native-stack": "^5.0.5",
"@react-navigation/stack": "^5.9.0",
"react-native": "0.63.2",

Now I downgraded to 2.5.0, will update here if the issue really stops.

ALSO - it's not related to the issue that the activity is killed in the background, I checked and it works fine there with the onCreate(null) solution.

@WoLewicki
Copy link
Member

Are you using "@react-navigation/native-stack": "^5.0.5",? The supported version of native-stack is taken from react-native-screens/native-stack. Does this issue happen there? If so, please provide a reproduction of this crash so we can work on it.

@WoLewicki WoLewicki added the Missing info The user didn't precise the problem enough label Sep 21, 2020
@lampn9397
Copy link

This issue occur also with me on Android devices.
"react-native-screens": "2.10.1"
image

@WoLewicki
Copy link
Member

@lampn9397 could you provide a repo with a reproduction of the issue then?

@WoLewicki WoLewicki added Platform: Android This issue is specific to Android Missing repro This issue need minimum repro scenario and removed Missing info The user didn't precise the problem enough labels Sep 21, 2020
@melkayam92
Copy link
Author

I can confirm that downgrade the library to 2.5.0 didn't help.

Looks like it's related to saveInstanceState..

Screen Shot 2020-09-22 at 20 37 45

@melkayam92
Copy link
Author

Also, I forgot to say, I did use the "animationEnabled" for my navigator in this version.

I will try to see what happens if I revert it to false.

@handipriyono
Copy link

handipriyono commented Oct 9, 2020

i also experienced this issue recently,
details:

  • "react-native-screens": "^2.9.0",
  • "react-native": "0.63.2",
  • "@react-navigation/stack": "^5.7.1",

Screenshot_2020-10-10 NullPointerException Attempt to invoke virtual method 'android view ViewParent android view View getP

it seems that the Author has mentioned it in their ReadMe.md file. about how to solve this issue.
For most people using an app built from the react-native template, that means editing MainActivity.java, likely located in android/app/src/main/java//MainActivity.java

You should add this code, which specifically discards any Activity state persisted during the Activity restart process, to avoid inconsistencies that lead to crashes.

  @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(null);
   }

@handipriyono
Copy link

sorry, i think the solution above still not resolved.
i still getting crash
Android: android.view.ViewParent android.view.View.getParent()' on a null object reference

@WoLewicki
Copy link
Member

Can you try and change https://github.com/software-mansion/react-native-screens/blob/master/android/src/main/java/com/swmansion/rnscreens/ScreenStackFragment.java#L157 to ViewParent screenStack = getView() != null ? getView().getParent() : null; and see if it fixes the issue?

@handipriyono
Copy link

i'll try, @WoLewicki , but, btw, if i change / modif in node_modules react-native screens repo, it means that, for the production-App, i have to clone that repo and use my repo instead of using from react-native-screen?

@WoLewicki
Copy link
Member

You can use patch-package until the version with a fix is released to automatically apply the change to your code.

@handipriyono
Copy link

@WoLewicki , thank for the solution, 👍🏼
unfortunatelly, this crash-case is random, so i can not make sure that that solution is working.,
but i still investigating into this issue,, and re-check my sentry if the crash still exist or not

@melkayam92
Copy link
Author

I can confirm that disabling the animation "fixes" the issues.

@WoLewicki
Copy link
Member

@melkayam92 can you check if having the animation and applying #671 fixes the bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Missing repro This issue need minimum repro scenario Platform: Android This issue is specific to Android
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants