The database is created using a SQLiteOpenHelper:
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
String SQL_CREATE_INVENTORY_TABLE = "CREATE TABLE " + InventoryEntry.TABLE_NAME + "("
+ InventoryEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ InventoryEntry.COLUMN_PRODUCT_IMAGE + " BLOB, "
+ InventoryEntry.COLUMN_PRODUCT_NAME + " TEXT NOT NULL, "
+ InventoryEntry.COLUMN_PRODUCT_PRICE + " REAL NOT NULL, "
+ InventoryEntry.COLUMN_PRODUCT_QUANTITY + " INTEGER, "
+ InventoryEntry.COLUMN_PRODUCT_DESCRIPTION + " TEXT);";
sqLiteDatabase.execSQL(SQL_CREATE_INVENTORY_TABLE);
}
All the constants are defined in a contract, this is the COLUMN_PRODUCT_IMAGE
one:
public static final String COLUMN_PRODUCT_IMAGE = "image";
In a CursorAdapter, I try to access the image
column from the bindView
method, after adding some random data to the database:
@Override
public void bindView(View view, final Context context, Cursor cursor) {
ImageView imageView = view.findViewById(R.id.product_image);
byte [] bytes = cursor.getBlob(cursor.getColumnIndexOrThrow(InventoryEntry.COLUMN_PRODUCT_IMAGE));
Bitmap bitmap = BitmapUtils.getBitmap(bytes);
imageView.setImageBitmap(bitmap);
}
This produces an java.lang.IllegalArgumentException: column 'image' does not exist
I double checked the database using windows cmd, here's how it looks:
sqlite> select * from inventory;
_id image name price quantity description
---------- ---------- ---------- ---------- ---------- -----------
1 ff 5.0 5 fds
Column 'image' exists, so why the error?