Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Getting below exception when permission is denied second time in fragment #244

Closed
lazy-coder-10 opened this issue Oct 30, 2019 · 6 comments · Fixed by #246
Closed

Getting below exception when permission is denied second time in fragment #244

lazy-coder-10 opened this issue Oct 30, 2019 · 6 comments · Fixed by #246
Labels

Comments

@lazy-coder-10
Copy link

lazy-coder-10 commented Oct 30, 2019

 java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=42, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } (has extras) }} to activity {com.shopfeur.user/com.karumi.dexter.DexterActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.finish()' on a null object reference
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4472)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4515)
        at android.app.ActivityThread.-wrap22(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1687)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.finish()' on a null object reference
        at com.karumi.dexter.DexterInstance.onPermissionsChecked(Unknown Source)
        at com.karumi.dexter.DexterInstance.updatePermissionsAsDenied(Unknown Source)
        at com.karumi.dexter.DexterInstance.onPermissionRequestDenied(Unknown Source)
        at com.karumi.dexter.Dexter.onPermissionsRequested(Unknown Source)
        at com.karumi.dexter.DexterActivity.onRequestPermissionsResult(Unknown Source)
        at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7434)
        at android.app.Activity.dispatchActivityResult(Activity.java:7260)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4468)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4515) 
        at android.app.ActivityThread.-wrap22(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1687) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6682) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 

@lazy-coder-10 lazy-coder-10 changed the title Getting below exception when permission is denied second time Getting below exception when permission is denied second time in fragment Oct 30, 2019
@pedrovgs pedrovgs added the bug label Nov 8, 2019
@pedrovgs
Copy link
Contributor

pedrovgs commented Nov 8, 2019

Hi @rohit6027 could you please provide more information about the error? What's the version of the library you are using when reproducing the error? Can you paste here the piece of code requesting the permission? Could you please list the steps to reproduce the error?

@rupinderjeet
Copy link

rupinderjeet commented Nov 29, 2019

Hi, I received this too a few moments ago. I am using an AppCompatActivity and I call this code when a button is tapped. Exception stack trace is same as above.

I am using Kotlin with MVVM.

Library: 'com.karumi:dexter:6.0.0'
OS: Android Emulator v9.0

Dexter.withActivity(this)
                .withPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
                .withListener(object: BasePermissionListener() {
                    override fun onPermissionGranted(response: PermissionGrantedResponse?) {
                        openProfileImageSelector()
                    }

                    override fun onPermissionDenied(response: PermissionDeniedResponse?) {
                        toast(R.string.error_perm_image_pick)
                    }
                })
                .check()

Reproducing:

  1. Request permission
  2. Deny it
  3. Re-trigger Step 1
  4. Deny
  5. Crash

You might have to do Step 3 & Step 4 about 2 - 4 times.

Is there any quick solution? I rely heavily on Dexter.

@pedrovgs
Copy link
Contributor

pedrovgs commented Nov 29, 2019

Hi @rohit6027 and @rupinderjeet I've sent a tentative fix for this error because even with the steps to reproduce you mentioned we are not able to reproduce the crash. I'd need you to try to reproduce this error in a demo project we can test manually and also to check if the new version we are going to publish as soon as #246 is merged fixes your issue. Please, if the PR I've sent doesn't fix the error, please reopen this issue.

@lazy-coder-10
Copy link
Author

lazy-coder-10 commented Nov 29, 2019

ok I will give you a demo project for this issue asap.

@lazy-coder-10
Copy link
Author

lazy-coder-10 commented Dec 1, 2019

Hi, @pedrovgs I have created a demo project for this exception. Please check it.

Step to produce Exception:-

  1. Permission dialog will be prompted when app launch
  2. deny permission
  3. dialog will be prompted again
  4. deny it again and app will be crashed.

[https://github.com/rohit6027/GlideException.git]

@pedrovgs
Copy link
Contributor

pedrovgs commented Dec 4, 2019

Thank you so much @rohit6027 your project helped me a lot to confirm the latest Dexter release fixed this issue. Update your app to use Dexter 6.0.1 and you won't ever see this error again.

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

Successfully merging a pull request may close this issue.

3 participants