我正在使用Sqlite数据库存储图像,并使用Cursor Loader从数据库从屏幕上加载图像。
但是我遇到了这个错误:
“ java.lang.IllegalStateException:无法从CursorWindow读取行0,第0列。在从游标访问数据之前,请确保游标已正确初始化。”
每当我尝试向数据库中插入1个或2个以上图像时 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);