vinzscam/react-native-file-viewer

Crash in Android

cuttingedge03 opened this issue · 10 comments

I am getting a lot of crashes on Android devices with NPE. Given below is the stack trace.

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.app.Activity.getPackageName()' on a null object reference
at com.vinzscam.reactnativefileviewer.RNFileViewerModule.open(RNFileViewerModule.java:55)
at java.lang.reflect.Method.invoke(Method.java)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
at com.facebook.react.bridge.queue.NativeRunnable.run(NativeRunnable.java)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:207)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
at java.lang.Thread.run(Thread.java:818)

Hi @cuttingedge03 I have the same issue. Do you have news? Thanks

@claudiozam Nothing yet. Nobody from the dev team has responded yet on this issue.

Hi,
it looks the package hasn't been linked correctly. Which version of RN are you using it? How have you linked the package? Are you using autolinking for other native packages?

@vinzscam I am using RN 0.63.3. It was happening on 0.63.2 as well. Yes, I am using auto-linking. It works fine normally. This is the issue coming for few production users from Play Store.

@vinzscam I am using RN 0.61.5

it looks your issue might be related to the flow in your application. Are you invoking any other specific library before opening RN file viewer? Is it possible to have a snippet of your code?

  let fileRemoteURLString = 'https://.............';

  let actualDownloadFileFetchBlobGet = RNFetchBlob.config({
    path: RNFetchBlob.fs.dirs.DocumentDir + '/my-tmp/myfile.pdf'
  }).fetch('GET', fileRemoteURLString);

  actualDownloadFileFetchBlobGet.then(resp => {
      FileViewer.open(resp.path(), { showOpenWithDialog: false, showAppsSuggestions: true })
      .then(() => {
        // success
      })
      .catch(errorFileViewer => {
        // log error
      });

  }).catch(errorRespFetchBlob => {
     // log error
  });

Hi, had a similar issue for a few weeks, finally found that another library intercepted a signal and made the app crash.
See there : react-native-image-picker/react-native-image-picker#1398
Solved by upgrading react-native-image-picker in my case, so check your other libraries.

@cuttingedge03 I have the similar issue in production

com.vinzscam.reactnativefileviewer.RNFileViewerModule.open
RNFileViewerModule.java, line 55
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.app.Activity.getPackageName()' on a null object reference

Stack trace

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:938
android.os.Handler.dispatchMessage Handler.java:99
com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage MessageQueueThreadHandler.java:27
android.os.Looper.loop Looper.java:246
com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run MessageQueueThreadImpl.java:226
java.lang.Thread.run Thread.java:923

Fixed by #124