java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.app.Activity.getPackageName()' on a null object reference
thegdznet opened this issue Β· 4 comments
thegdznet commented
Hi!
Firstly, thanks for your work on this project!
Today I used patch-package to patch react-native-file-viewer@2.1.4
for the project I'm working on based on a crash log collected via AppCenter.
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.app.Activity.getPackageName()' on a null object reference
com.vinzscam.reactnativefileviewer.RNFileViewerModule.open RNFileViewerModule.java:55
java.lang.reflect.Method.invoke Method.java
com.facebook.react.bridge.JavaMethodWrapper.invoke JavaMethodWrapper.java:372
com.facebook.react.bridge.JavaModuleWrapper.invoke JavaModuleWrapper.java:151
com.facebook.react.bridge.queue.NativeRunnable.run NativeRunnable.java
android.os.Handler.handleCallback Handler.java:883com.vinzscam.reactnativefileviewer.RNFileViewerModule.open RNFileViewerModule.java:55
java.lang.reflect.Method.invoke Method.java
com.facebook.react.bridge.JavaMethodWrapper.invoke JavaMethodWrapper.java:372
com.facebook.react.bridge.JavaModuleWrapper.invoke JavaModuleWrapper.java:151
com.facebook.react.bridge.queue.NativeRunnable.run NativeRunnable.java
android.os.Handler.handleCallback Handler.java:883
Here is the diff that solved my problem:
diff --git a/node_modules/react-native-file-viewer/android/build/.transforms/26621e9c688a9714df136801936f5f38.bin b/node_modules/react-native-file-viewer/android/build/.transforms/26621e9c688a9714df136801936f5f38.bin
new file mode 100644
index 0000000..5ff383e
--- /dev/null
+++ b/node_modules/react-native-file-viewer/android/build/.transforms/26621e9c688a9714df136801936f5f38.bin
@@ -0,0 +1 @@
+o/debug
diff --git a/node_modules/react-native-file-viewer/android/build/.transforms/26621e9c688a9714df136801936f5f38/debug/com/vinzscam/reactnativefileviewer/BuildConfig.dex b/node_modules/react-native-file-viewer/android/build/.transforms/26621e9c688a9714df136801936f5f38/debug/com/vinzscam/reactnativefileviewer/BuildConfig.dex
new file mode 100644
index 0000000..cbeabb4
Binary files /dev/null and b/node_modules/react-native-file-viewer/android/build/.transforms/26621e9c688a9714df136801936f5f38/debug/com/vinzscam/reactnativefileviewer/BuildConfig.dex differ
diff --git a/node_modules/react-native-file-viewer/android/build/.transforms/26621e9c688a9714df136801936f5f38/debug/com/vinzscam/reactnativefileviewer/FileProvider.dex b/node_modules/react-native-file-viewer/android/build/.transforms/26621e9c688a9714df136801936f5f38/debug/com/vinzscam/reactnativefileviewer/FileProvider.dex
new file mode 100644
index 0000000..9d72548
Binary files /dev/null and b/node_modules/react-native-file-viewer/android/build/.transforms/26621e9c688a9714df136801936f5f38/debug/com/vinzscam/reactnativefileviewer/FileProvider.dex differ
diff --git a/node_modules/react-native-file-viewer/android/build/.transforms/26621e9c688a9714df136801936f5f38/debug/com/vinzscam/reactnativefileviewer/RNFileViewerModule$1.dex b/node_modules/react-native-file-viewer/android/build/.transforms/26621e9c688a9714df136801936f5f38/debug/com/vinzscam/reactnativefileviewer/RNFileViewerModule$1.dex
new file mode 100644
index 0000000..0ff1a95
Binary files /dev/null and b/node_modules/react-native-file-viewer/android/build/.transforms/26621e9c688a9714df136801936f5f38/debug/com/vinzscam/reactnativefileviewer/RNFileViewerModule$1.dex differ
diff --git a/node_modules/react-native-file-viewer/android/build/.transforms/26621e9c688a9714df136801936f5f38/debug/com/vinzscam/reactnativefileviewer/RNFileViewerModule.dex b/node_modules/react-native-file-viewer/android/build/.transforms/26621e9c688a9714df136801936f5f38/debug/com/vinzscam/reactnativefileviewer/RNFileViewerModule.dex
new file mode 100644
index 0000000..039c738
Binary files /dev/null and b/node_modules/react-native-file-viewer/android/build/.transforms/26621e9c688a9714df136801936f5f38/debug/com/vinzscam/reactnativefileviewer/RNFileViewerModule.dex differ
diff --git a/node_modules/react-native-file-viewer/android/build/.transforms/26621e9c688a9714df136801936f5f38/debug/com/vin
vinzscam commented
Hi!
thank you for reporting the issue.
Do you have more information about the changes you've made for fixing the issue? Unfortunately the diff above doesn't show anything useful.
thegdznet commented
Hi,
As You can see in the crash log, we were facing a NPE in RNFileViewerModule.open method when invoking getCurrentActivity().getPackageName().
To avoid this crash and to follow the philosophy of Your code, I just added following line at the beginning of RNFileViewerModule.open method:
if (getCurrentActivity() == null) {
sendEvent(OPEN_EVENT, currentId, "No Current Activity");
}
Regards,
Guillaume DROULEZ
Mobile Lead Developer
+33 6 66 18 69 06
***@***.***
Skype: thegdz.net
Twitter: @thegdznet
http://www.thegdz-net.com
β¦ Le 20 oct. 2021 Γ 23:46, Vincenzo Scamporlino ***@***.***> a Γ©crit :
Hi!
thank you for reporting the issue.
Do you have more information about the changes you've made for fixing the issue? Unfortunately the diff above doesn't show anything useful.
β
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#117 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAVMLXEZ7KXFCEVFTYI2243UH42C5ANCNFSM5EKNAF4A>.
Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
thegdznet commented
Thanks a lot!