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

NullPointerException - Samsung Galaxy S4 - Android 5.0.1 #9

Open
er-mo opened this issue May 27, 2018 · 4 comments
Open

NullPointerException - Samsung Galaxy S4 - Android 5.0.1 #9

er-mo opened this issue May 27, 2018 · 4 comments

Comments

@er-mo
Copy link

er-mo commented May 27, 2018

05-27 14:45:15.592 6787-6787/com.myhexaville.androidimagepicker E/AndroidRuntime: FATAL EXCEPTION: main Process: com.myhexaville.androidimagepicker, PID: 6787 java.lang.RuntimeException: Unable to resume activity {com.myhexaville.androidimagepicker/com.myhexaville.androidimagepicker.activity_example.ActivityExample}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=200, result=-1, data=null} to activity {com.myhexaville.androidimagepicker/com.myhexaville.androidimagepicker.activity_example.ActivityExample}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.myhexaville.smartimagepicker.ImagePicker.handleActivityResult(int, int, android.content.Intent)' on a null object reference at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3394) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3425) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2763) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4462) at android.app.ActivityThread.access$1000(ActivityThread.java:177) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1454) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5942) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=200, result=-1, data=null} to activity {com.myhexaville.androidimagepicker/com.myhexaville.androidimagepicker.activity_example.ActivityExample}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.myhexaville.smartimagepicker.ImagePicker.handleActivityResult(int, int, android.content.Intent)' on a null object reference at android.app.ActivityThread.deliverResults(ActivityThread.java:4058) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3380) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3425)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2763)  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4462)  at android.app.ActivityThread.access$1000(ActivityThread.java:177)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1454)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:145)  at android.app.ActivityThread.main(ActivityThread.java:5942)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.myhexaville.smartimagepicker.ImagePicker.handleActivityResult(int, int, android.content.Intent)' on a null object reference at com.myhexaville.androidimagepicker.activity_example.ActivityExample.onActivityResult(ActivityExample.java:31) at android.app.Activity.dispatchActivityResult(Activity.java:6549) at android.app.ActivityThread.deliverResults(ActivityThread.java:4054) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3380)  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3425)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2763)  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4462)  at android.app.ActivityThread.access$1000(ActivityThread.java:177)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1454)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:145)  at android.app.ActivityThread.main(ActivityThread.java:5942)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) 

@ashishparmar
Copy link

Same error I am getting in OS 6. Is there any solution?

@Omid3d
Copy link

Omid3d commented Jun 8, 2018

Probably after taking camera image or picking image from gallery, the device was rotated, so the activity is destroyed and the ImagePicker object is null.
To solve this issue try to initialize this object (if is null) wherever you want to access to that.

Good luck

@SalvatoreAD
Copy link

This is a problem that many samsung have, as their camera app, rotates to take a picture. I tried to save the state, but it is not a serializable object.

@Omid3d do you have some ideas?

@Omid3d
Copy link

Omid3d commented Jun 28, 2018

Yes you can't serialize this object and you shouldn't. My recommendation is to recreate object wherever you want to access that. Because after camera rotates you just need to call ImagePicker.handleActivityResult in onActivityResult and I think we can safely get the result from intent. Also think about image pick callback, can we save state of a callback? Maybe no!
So the simplest solution is to initialize the object again.
For example you can create a method like following:

ImagePicker ip = null;
Uri selectedImageUri = null;
private ImagePicker getImagePicker() {
        if (ip == null) {
            ip = new ImagePicker(this,
                    null,
                    imageUri -> {/*on image picked */
                        selectedImageUri = imageUri;
                    })
                    .setWithImageCrop(
                            16 /*aspect ratio x*/,
                            9 /*aspect ratio y*/);
        }
        return ip;
    }

and then whenever you want to access to this ImagePicker object call this method and instead of serializing ImagePicker object or something else, just save state of selectedImageUri or taken image uri in activity. So after onActivityResult called you have your object and it can handle the result without any problem. Also don't forget to first call this method in oncreate (to ensure you receive callback from ImagePicker).

I hope my answer as a workaround can help you to solve this problem.
Good luck

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

4 participants