question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullPointerException when showing Android Modal

See original GitHub issue

Description

We are getting a NullPointerException sometimes upon trying to show a modal (see “Reproduction” section for details).

Stack Trace:

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.facebook.react.uimanager.ReactShadowNode.setStyleWidth(float)' on a null object reference
	at com.facebook.react.uimanager.UIImplementation.updateNodeSize(UIImplementation.java:151)
	at com.facebook.react.uimanager.UIManagerModule.updateNodeSize(UIManagerModule.java:213)
	at com.facebook.react.views.modal.ReactModalHostView$DialogRootViewGroup$1.run(ReactModalHostView.java:301)
	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:148)
	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196)
	at java.lang.Thread.run(Thread.java:818)

It sounds like this commit may be related, and may have fixed a similar issue: https://github.com/facebook/react-native/commit/922cd6ddfc2414d274a53a5a6259ad50cb232782 From that commit message:

In some cases, the size of the content view changes before we add views to the Modal. That means that the size of that view will not be set through the onSizeChanged method. This can result in some apps apparently freezing, since the dialog is created, but there are no actual views in it.

The part about “dialog is created, but there are no actual views in it” makes me feel it’s related, because the NullPointerException happens here: https://github.com/facebook/react-native/blob/v0.36.0/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java#L301-L302 So apparently getChildAt(0).getId() returns an ID that is unavailable by the time setStyleWidth is called.

Reproduction

Unfortunately, it’s a tough case to reproduce. Even in our app it only happens about half the time. We have one modal show first, and when the user clicks “OK” on that one, we show another “saving” modal, then when saving is complete we remove the modal. It seems in between the user clicking “OK” and the “saving” modal displaying, we get a crash (about half the time).

Additional Information

  • React Native version: v0.36.0
  • Platform: Android (tested on Nexus 5)
  • Operating System: Android (Tried genymotion, but can only reproduce on a real device)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:24
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
butchmarshallcommented, Apr 3, 2017

I get this crash randomly while using react-native-loading-spinner-overlay

1reaction
JakeRawrcommented, Feb 17, 2017

+1, This happens for me even if visible = { false }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Showing null pointer exception in setting the value in model ...
In your activity class you defined CatModel as: private CategoryModel catModel;. Which would initialize catModel with null.
Read more >
Fix "java.lang.NullPointerException" in Android Studio
Try: The Try block executes a piece of code that is likely to crash or a place where the exception occurs. Catch: The...
Read more >
NullPointerException - Android Developers
NullPointerException objects may be constructed by the virtual machine as if stack trace was ... Constructs a NullPointerException with no detail message.
Read more >
Java.Lang.NullPointerException when show Popup.
- I call my method DisplayAlert when Load application. My Page.Content is SfPopupLayout (X) , but when MainActivity call method LoadApplication( ...
Read more >
Java NullPointerException - Detect, Fix, and Best Practices
The below image shows the null pointer exception when the above program is ... POST) public String user(@Validated User user, Model model) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found