I have a program that allows the user to pick images from the gallery, saves it in a database and shows it on screen. This works for most images , but for certain images, the app crashes. There is no error message in the Logcat. But when i restart the app, i get a error message that says:
Couldn't read row 0, col 1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
(Tested on ANDROID SDK 24)
new AlertDialog.Builder(this).setTitle("Take or Pick?").setMessage("Choose to click a new picture or choose from existing").
setNegativeButton("CHOOSE PHOTO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent i = new Intent(
Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, REQUEST_IMAGE_PICKER);
}
}).create().show();
onActivityResult code goes like this:
if (requestCode == REQUEST_IMAGE_PICKER && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
Bitmap bmp= null;
try { //GET BITMAP FROM URI , TRY CATCH USED TO TACKLE
bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(selectedImage)); // IO STREAM FILE NOT FOUND ERROR
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if(cameraTeamStatus==1) {
img1.setImageBitmap(bmp); //SET IMAGE
image1_to_save = convertToBlob(bmp); //CONVERT TO BLOB
}