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.

java.lang.NullPointerException crash in Android WebView

See original GitHub issue

Bug description: Hello, upon looking at app crashes in google play console, I am getting following crash log from the users:

com.facebook.react.bridge.JSApplicationIllegalArgumentException: 
  at com.facebook.react.uimanager.ViewManagersPropertyCache$PropSetter.updateViewProp (ViewManagersPropertyCache.java:98)
  at com.facebook.react.uimanager.ViewManagerPropertyUpdater$FallbackViewManagerSetter.setProperty (ViewManagerPropertyUpdater.java:134)
  at com.facebook.react.uimanager.ViewManagerPropertyUpdater.updateProps (ViewManagerPropertyUpdater.java:54)
  at com.facebook.react.uimanager.ViewManager.updateProperties (ViewManager.java:48)
  at com.facebook.react.uimanager.NativeViewHierarchyManager.createView (NativeViewHierarchyManager.java:278)
  at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute (UIViewOperationQueue.java:179)
  at com.facebook.react.uimanager.UIViewOperationQueue$1.run (UIViewOperationQueue.java:773)
  at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches (UIViewOperationQueue.java:888)
  at com.facebook.react.uimanager.UIViewOperationQueue.access$2200 (UIViewOperationQueue.java:42)
  at com.facebook.react.uimanager.UIViewOperationQueue$2.runGuarded (UIViewOperationQueue.java:846)
  at com.facebook.react.bridge.GuardedRunnable.run (GuardedRunnable.java:29)
  at android.os.Handler.handleCallback (Handler.java:873)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:227)
  at android.app.ActivityThread.main (ActivityThread.java:7212)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:575)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:887)

Caused by: java.lang.reflect.InvocationTargetException: 
  at java.lang.reflect.Method.invoke (Native Method)
  at com.facebook.react.uimanager.ViewManagersPropertyCache$PropSetter.updateViewProp (ViewManagersPropertyCache.java:83)

Caused by: java.lang.NullPointerException: 
  at com.reactnativecommunity.webview.RNCWebViewManager.setupWebChromeClient (RNCWebViewManager.java:652)
  at com.reactnativecommunity.webview.RNCWebViewManager.setAllowsFullscreenVideo (RNCWebViewManager.java:519)
  at .CPU
  at .29
  at .27
  at .14
  at .10
  at .10
  at 8.5
  at 5.8
  at .5
  at 3.5
  at 4.5
  at 4.3
  at .4
  at 2.8
  at 2.6
  at 1.3
  at 1.7
  at 1.7
  at 1.2
  at 1.4
  at 1.3
  at 0.3
  at 1.2
  at 1.1
  at .1
  at .1

seems to be caused by react native webview.

Environment:

  • OS: MacOS
  • OS version: 10.15.4
  • react-native version: 0.61.5
  • react-native-webview version: 9.4.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
akreadcommented, Aug 3, 2020

Has anyone else seen this bug? I am getting reports of the same crash in my app.

Error while updating property 'allowsFullscreenVideo' of a view managed by: RNCWebView
java.lang.NullPointerException
Attempt to invoke virtual method 'int android.app.Activity.getRequestedOrientation()' on a null object reference

https://github.com/react-native-community/react-native-webview/blob/master/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java#L674 appears to be the source of the issue - calling getRequestedOrientation() on a null activity.

react-native version: 0.62.2 react-native-webview version: 8.1.2

I know there are newer versions of react-native-web-view but that code there doesn’t seem to have really changed.

Can we re-open this issue?

6reactions
JakeStoefflercommented, Nov 19, 2020

+1 to re-opening the issue. Confirmed this issue still exists in react-native-webview 10.9.3 with react-native 0.63.3

I was able to use patch-package to work around it:

diff --git a/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java b/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java
index e042a50..0ada70a 100644
--- a/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java
+++ b/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java
@@ -566,6 +566,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
     WebView view,
     @Nullable Boolean allowsFullscreenVideo) {
     mAllowsFullscreenVideo = allowsFullscreenVideo != null && allowsFullscreenVideo;
+    if (((ReactContext)view.getContext()).getCurrentActivity() == null) mAllowsFullscreenVideo = false;
     setupWebChromeClient((ReactContext)view.getContext(), view);
   }

Unfortunately it means fullscreen video may not always be available in Android, but for our use case, it’s better than the app crashing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webview android application crashes with error "java.lang ...
It is a simple app to display a website with WebView. The application runs for a while but when I continue using it,...
Read more >
WebView crashes due to NPE [36920839] - Issue Tracker
Android build version: 2.2. Device: inc. Exception occured in thread WebViewWorkerThread java.lang.NullPointerException at android.webkit.WebViewDatabase.
Read more >
When we upgraded AdMob, we found some ... - Google Groups
Fatal Exception : java.lang.NullPointerException: Attempt to invoke interface method 'void com.google.android.gms.ads.internal.webview.
Read more >
521753 - Forcing a locale with applyOverrideConfiguration ...
Process: tdr.com.tdrtestwebviewcrash, PID: 31541 java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.
Read more >
flutter_inappwebview 5.4.3+1 | Flutter Package - Pub.dev
5.4.3+1 #. Fixed "Latest version 5.4.3 crashes on Android" #1159 ... Fixed wrong usage of Android WebView scale property; Fixed "java.lang.
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