app crashes when going back from gallery without selecting any image

前端 未结 3 1301
迷失自我
迷失自我 2021-01-29 09:39

when ever i am not selecting any image after opening the gallery and goin back my app crashes. plz help me out guys. this is a program to upload image to server selecting from a

3条回答
  •  太阳男子
    2021-01-29 09:47

    You can handle it this way:

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 1 && resultCode == RESULT_OK && data != null) {
            //your code
        }
        else {
            //alert of "No image was selected"
        }
    }
    

    Don't perform any operation on data if its null. So it won't give a crash.

    Hope it helps.

提交回复
热议问题