0

I'm using Sqlite database to store image and using Cursor Loader to load image int o the Screen from the database.

But I'm getting this error :

"java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it."

When ever I'm trying to insert more than 1 or 2 image into the database My Cursor Adapter Class

     ImageView imageView = view.findViewById(R.id.item_image);
    TextView textView = view.findViewById(R.id.item_name);

    //Fetching the values from the cursor
    String name = cursor.getString(cursor.getColumnIndex(ItemEntry.COLUMN_NAME));
    byte[] image = cursor.getBlob(cursor.getColumnIndex(ItemEntry.COLUMN_IMAGE));


    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    options.inSampleSize = calculateInSampleSize(options, 500, 500);
    options.inJustDecodeBounds = false;
    Bitmap imageBitmap = BitmapFactory.decodeByteArray(image, 0, image.length, options);

    //Populate the views
    imageView.setImageBitmap(imageBitmap);
    textView.setText(name);
Harsha Bhadra
  • 223
  • 2
  • 5
  • 13
  • Storing images in a database is not a good idea. https://stackoverflow.com/questions/21432556/android-java-lang-illegalstateexception-couldnt-read-row-0-col-0-from-cursorw – Mike M. Nov 18 '18 at 16:26
  • Are you sure your query returned any rows? – Shawn Nov 18 '18 at 18:03
  • Yes query returns rows and it's populating the listView also but after storing 1 or 2 items it's giving this error – Harsha Bhadra Nov 18 '18 at 18:15
  • @MikeM. Is there any way to resize the image so that the row size in the database will be 2mb max?? – Harsha Bhadra Nov 19 '18 at 03:23
  • It's not just a single row size. It's the size for the whole `Cursor`. Even if you shrink those images, the more you add, the more likely you'll run into that same problem again. The solution is to just not store images in a database. Store them as files, and keep their file paths in the database. – Mike M. Nov 19 '18 at 03:30

0 Answers0