Skip to content
Advertisement

NullPointerException while selecting image from the storage for the Second time onwards, No NullPointerException while selecting First time

I have set up a button that is meant to check for READ_EXTERNAL_STORAGE permissions, and then open the users phone storage display images. I’ve done this successfully via the following code:

All of this works perfectly on the first try. The user sees the permission dialog box, presses agree and the image selector opens displaying images on their phone! However, the second time we try to use the same button the app crashes. So basically after the permissions are granted the app crashes every time the button is pressed.

The following error is displayed:

JavaScript

BottomTabView.java

JavaScript

I did a log.d to identify where it fails, please refer to previous code to see log.d.

How can I overcome this issue?

EDIT:

HomeActivity:

JavaScript

Advertisement

Answer

Your else statement is currently like this, which means you are trying to create a new instance of HomeActivity and call selectimage(), and it does not work that way.

JavaScript

Please, change it to

JavaScript

Please, try this, this should solve your problem.

EDIT: Use of interface and listener pattern

In your BottomTabView add the following

JavaScript

Add the following in your HomeActivity

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement