Using "react-native-image-picker": "^0.18.3"
I try to select an image from the device library, when selecting an image - the app crashes. This only happens on the device and not in the simulator.
Here is the error:
Fatal Exception: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { dat=content: flg=0x1 }} to activity {com.myapp/com.myapp.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:3881)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3931)
at android.app.ActivityThread.access$1300(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1408)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at com.imagepicker.ImagePickerModule.getResizedImage(ImagePickerModule.java:504)
at com.imagepicker.ImagePickerModule.onActivityResult(ImagePickerModule.java:388)
at com.facebook.react.bridge.ReactContext.onActivityResult(ReactContext.java:173)
at com.facebook.react.ReactInstanceManagerImpl.onActivityResult(ReactInstanceManagerImpl.java:526)
at com.facebook.react.ReactActivity.onActivityResult(ReactActivity.java:180)
at com.myapp.MainActivity.onActivityResult(MainActivity.java:105)
at android.app.Activity.dispatchActivityResult(Activity.java:6160)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3877)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3931)
at android.app.ActivityThread.access$1300(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1408)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Another test with "react-native-image-picker": "^0.18.6" gives me the same error...
+1
What kind of image ?
@yfuks Seems to be any photo based on the stacktraces we are seeing. Hard to tell exactly since the path is something like content://media/external/images/media/7396. I don't have an Android device to test different file types at the moment though.
If I can help in any way let me know. We just did a soft-launch of our Android app yesterday, and have already seen this crash 92 times for 45 different users on a variety of devices and Android versions:

A fast work around is to not set the folowingoptions :
angle
maxWidth
maxHeight
quality
I'm actually working on a fix :)
Can you guys tell me if you get the same issue with the example ? It could help me.
I can't test the example at the moment, but I just published a new APK with the workaround you suggested (we used quality), so hopefully that will work for now.
Make sure you add the folowing permission
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Since i'm not able to reproduce i will add robustness code to the project to avoid crash.
I just push robustness code to fix this issue that appears in the case you can't read the selected image.
https://github.com/marcshilling/react-native-image-picker/commit/f134b9158cb29144fc12f9112f690c0bdef8ea79#diff-e2ac0feb8ce151bd872a7c4ab6b4801dR400
Hope this will work.
@yfuks well, this will prevent the crash...but it's not going to help these guys actually get the image. Do we know the root cause?
Well the code that i push will just prevent resizing if we cannot read the selected image. I feel like it could be helpfull since it don't prevent from getting response infos (base64...)
The crash can only appear when we can't read the selected photo. (No rights, not enough memory)
@yfuks ohhh I see, I didn't see that it avoids the resize if we can't read it. Cool.
I'm going to publish a new release to npm right now...@CodeTitanian @anativ @dhrrgn can you guys see if this fixes your issue?
@marcshilling if you can just wait a couple of minutes :)
I'm on @jeremyeaton89 PR actually. Probably going to merge soon
@yfuks oops, too late! v0.18.9 is live with the robustness changes for this issue. I'll leave it to you to publish the next patch!
@yfuks I did have the <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> permission.
@marcshilling I installed module version 0.18.10 and now the app does not crash but also does not really do anything...
Removing the options you suggested:
angle
maxWidth
maxHeight
quality
Does not help because the response data I get is empty string.
@yfuks that's what I was talking about ^. You fixed the crash but that root cause is that the photo doesn't exist.
@CodeTitanian
does not really do anything
What you mean exactly ? Nothing is returned to RN ?
@marcshilling
the photo doesn't exist
I'm not sure about that. And avoid crash is still an enhancement :)
@CodeTitanian can you tell me what kind of image you pick in your gallery ? Image from facebook ? Camera ? .. ?
@yfuks When I select a photo from "Gallery" it works and brings up the cropping tool (with allowsEditing option). When I select from the Photos app it does not work and does not open the cropping tool (even with allowsEditing option enabled).
Same photo as far as I can tell ... Just matters which picture app I go thru.
@rpastorelle can you open an other issue ? :)
@yfuks He was just giving you the information you asked for. It is the same issue.
He was just giving you the information you asked for. It is the same issue.
ok.
So now that we have something to work with i can investigate further and try to reproduce.
Good new i'm finally able to reproduce the issue ! I also know what can i do to fix it. I'm on it. :)
fix in 0.18.11
So i fix the issue by using the initial image if the crop don't perform. I still need to find out why crop don't work on some app.
Can you try the new version and tell me if it resolve your issue ?
@yfuks Can confirm this has fixed the issue for us. Thanks for the quick turn-around on this. 馃憤
@yfuks the new version works good. Thanks for fixing it!
I'm getting this exact same error now on version 0.19.2. Any idea what could be causing it?
@smwoods nothing appears to have changed with the code that was added to fix this, and I can't reproduce. Let me know if you can track it down.
Hm. I'm running on a galaxy s6, react native version 0.26.3, I've tried uninstalling and reinstalling multiple times, and I'm running the example exactly as written. Every time I select a photo, the app crashes. Any advice on how to begin debugging this at least?
Reinstalled Android Studio, finally got it working. Still crashes with allowsEditing on but is working otherwise.
Most helpful comment
Another test with "react-native-image-picker": "^0.18.6" gives me the same error...