0

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
        }
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Deeraj Theepshi
  • 183
  • 3
  • 10

1 Answers1

0

This crash is due to large size of picture taken by camera and cursor not able to handle it ,cursor initialize fails.

In order to fix this I would suggest considering one of the following methods to reduce image size before upload Link:1 , Link:2 ,Link:3 or you can check this link Whatsapp like Image Compression.

Hope it Helps!