我已经获得许可
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
但是开放失败:ENOENT (No such file or directory)
try {
dbmanager = new DBManager(this);
sqlitedb = dbmanager.getReadableDatabase();
Cursor cursor = sqlitedb.query("photos", null, null, null, null, null, "title");
int i = 0;
while(cursor.moveToNext()) {
String str_title = cursor.getString(cursor.getColumnIndex("title"));
String str_orientation = cursor.getString(cursor.getColumnIndex("orientation"));
String str_background = cursor.getString(cursor.getColumnIndex("background"));
String str_path = cursor.getString(cursor.getColumnIndex("path"));
LinearLayout layout_list = new LinearLayout(this);
layout_list.setOrientation(LinearLayout.HORIZONTAL);
layout_list.setPadding(20, 10, 20, 10);
layout_list.setId(i);
layout_list.setTag(str_title);
ImageView iv_photo = new ImageView(this);
Uri uriFromPath = Uri.fromFile(new File(str_path));
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uriFromPath));
Bitmap thumb = Bitmap.createScaledBitmap(bitmap, 200, 200, true);
iv_photo.setImageBitmap(thumb);
layout_list.addView(iv_photo);
} catch (FileNotFoundException e) {
Toast.makeText(this, "error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
答案 0 :(得分:1)
No such file or directory
您尝试访问的文件不存在。我会检查构建文件路径的代码,并确保它是外部存储的有效文件路径