i have to button : first button is for save image from gallery to database , second button is for show images from database in imageView but My problem with the second button is the error this line : "Bitmap bitmapImage = BitmapFactory.decodeFile(imageFile.toString());"
in logcat error :
"E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: [B@c97f202: open failed: ENOENT (No such file or directory)"
Database code :
private static String dbNAME = "myDB.db";
private static String tableName = "imageColumns";
private static String imageColumnName = "image";
private Bitmap bitmap;
private int i = 1;
db = this.openOrCreateDatabase(dbNAME, SQLiteDatabase.CREATE_IF_NECESSARY, null);
db.setVersion(1);
db.setLocale(Locale.getDefault());
String createTable = "create table if not exists imageColumns(id INTEGER PRIMARY KEY AUTOINCREMENT , image TEXT)";
db.execSQL(createTable);
First Button(save Image) code :
public void save(View view) {
if (bitmap != null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
byte[] byteImage = stream.toByteArray();
ContentValues values = new ContentValues();
values.put(imageColumnName, String.valueOf(byteImage));
db.insert(tableName, null, values);
Toast.makeText(this, "Save", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Save Image First!", Toast.LENGTH_SHORT).show();
}
}
Second Button(show Image) code :
public void showImage(View view) {
Cursor cursor2 = db.rawQuery("select * from imageColumns where id = " + i, null);
if (cursor2.getCount() != 0) {
while (cursor2.moveToNext()) {
Toast.makeText(this, "number of images" + i, Toast.LENGTH_SHORT).show();
String path = cursor2.getString(cursor2.getColumnIndex(imageColumnName));
File imageFile = new File(path);
Bitmap bitmapImage = BitmapFactory.decodeFile(imageFile.toString());
imageView.setImageBitmap(bitmapImage); //this line is problem
}
i++;
}
}