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
Try this, add if(resultCode == RESULT_OK)
:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK){ //<-- Add this
if (requestCode == 1 ) {
//Bitmap photo = (Bitmap) data.getData().getPath();
Uri selectedImageUri = data.getData();
imagepath = getPath(selectedImageUri);
Bitmap bitmap=BitmapFactory.decodeFile(imagepath);
imageview.setImageBitmap(bitmap);
// messageText.setText("Uploading file path:" +imagepath);
}
}
}
In your current code , even if the result code is not OK
its executing data.getData()
which is null