Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference #165

Closed
CodeTitanian opened this issue Apr 6, 2016 · 29 comments

Comments

@CodeTitanian
Copy link

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)
@CodeTitanian
Copy link
Author

Another test with "react-native-image-picker": "^0.18.6" gives me the same error...

@anativ
Copy link

anativ commented Apr 6, 2016

+1

@CodeTitanian CodeTitanian changed the title Trying to select an image from library on HTC Mate crashs Trying to select an image from library on HTC M8 crashs Apr 6, 2016
@marcshilling marcshilling changed the title Trying to select an image from library on HTC M8 crashs [Android] Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference Apr 6, 2016
@yfuks
Copy link
Contributor

yfuks commented Apr 6, 2016

What kind of image ?

@dhrrgn
Copy link

dhrrgn commented Apr 6, 2016

@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:

@yfuks
Copy link
Contributor

yfuks commented Apr 6, 2016

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.

@dhrrgn
Copy link

dhrrgn commented Apr 6, 2016

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.

@yfuks
Copy link
Contributor

yfuks commented Apr 6, 2016

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.

@yfuks
Copy link
Contributor

yfuks commented Apr 6, 2016

I just push robustness code to fix this issue that appears in the case you can't read the selected image.

f134b91#diff-e2ac0feb8ce151bd872a7c4ab6b4801dR400

Hope this will work.

@marcshilling
Copy link
Contributor

@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?

@yfuks
Copy link
Contributor

yfuks commented Apr 6, 2016

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)

@marcshilling
Copy link
Contributor

@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?

@yfuks
Copy link
Contributor

yfuks commented Apr 6, 2016

@marcshilling if you can just wait a couple of minutes :)
I'm on @jeremyeaton89 PR actually. Probably going to merge soon

@marcshilling
Copy link
Contributor

@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!

@CodeTitanian
Copy link
Author

@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.

@marcshilling
Copy link
Contributor

@yfuks that's what I was talking about ^. You fixed the crash but that root cause is that the photo doesn't exist.

@yfuks
Copy link
Contributor

yfuks commented Apr 7, 2016

@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 :)

@yfuks
Copy link
Contributor

yfuks commented Apr 7, 2016

@CodeTitanian can you tell me what kind of image you pick in your gallery ? Image from facebook ? Camera ? .. ?

@rpastorelle
Copy link

@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.

@yfuks
Copy link
Contributor

yfuks commented Apr 7, 2016

@rpastorelle can you open an other issue ? :)

@dhrrgn
Copy link

dhrrgn commented Apr 7, 2016

@yfuks He was just giving you the information you asked for. It is the same issue.

@yfuks
Copy link
Contributor

yfuks commented Apr 7, 2016

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.

@yfuks
Copy link
Contributor

yfuks commented Apr 8, 2016

Good new i'm finally able to reproduce the issue ! I also know what can i do to fix it. I'm on it. :)

@yfuks
Copy link
Contributor

yfuks commented Apr 8, 2016

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 ?

@dhrrgn
Copy link

dhrrgn commented Apr 8, 2016

@yfuks Can confirm this has fixed the issue for us. Thanks for the quick turn-around on this. 👍

@yfuks yfuks closed this as completed Apr 8, 2016
@CodeTitanian
Copy link
Author

@yfuks the new version works good. Thanks for fixing it!

@smwoods
Copy link

smwoods commented Jun 10, 2016

I'm getting this exact same error now on version 0.19.2. Any idea what could be causing it?

@marcshilling
Copy link
Contributor

@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.

@smwoods
Copy link

smwoods commented Jun 11, 2016

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?

@smwoods
Copy link

smwoods commented Jun 12, 2016

Reinstalled Android Studio, finally got it working. Still crashes with allowsEditing on but is working otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants