[Android] Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
See original GitHub issueUsing “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)
Issue Analytics
- State:
- Created 7 years ago
- Comments:29 (17 by maintainers)
Top Results From Across the Web
Attempt to invoke virtual method 'int android.graphics.Bitmap ...
The problem you are facing is that you are trying to getWidth() on your unscaledBitmap in the createScaledBitmap function.
Read more >Attempt to invoke virtual method 'int android.graphics.Bitmap ...
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference #49. Open.
Read more >int android.graphics.Bitmap.getWidth() - Issue Tracker
Error: java.lang.NullPointerException:Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
Read more >Attempt to invoke virtual method ''int android.graphics.Bitmap ...
NullPointerException: Attempt to invoke virtual method ''int android.graphics.Bitmap.getWidth()'' on a null object reference at android.graphics.Bitmap.
Read more >Attempt to invoke virtual method 'int android.graphics.Bitmap ...
getWidth ()' on a null object reference. androidandroid-activityandroid-bitmapnullpointerexception. I have BitmapScalingHelper.java:
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another test with “react-native-image-picker”: “^0.18.6” gives me the same error…
@yfuks Can confirm this has fixed the issue for us. Thanks for the quick turn-around on this. 👍