I select an image from the gallery and save the path in Sqlite
and so far everything is fine, the problem comes when trying to load the image, it is shown ImageView
empty and on Logcat
receipt twice:
Unable to decode stream: java.io.FileNotFoundException: : open failed: ENOENT (No such file or directory)
Make it clear that Manifest
I have the permissions:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
And in the application I have the permissions granted.
The code when I try to load the image:
private String ruta_imagen = "";
// obtengo todo lo demás correctamente, menos la imagen:
if (notas != null) {
ed_titulo.setText(notas.getTitulo());
ed_nota.setText(notas.getNotas());
tv_fecha.setText(notas.getFecha());
tv_persistente.setText(notas.getPersistente());
tv_categoria.setText(notas.getCategoria());
image1.setImageBitmap(crearThumb());
}
private Bitmap getBitmap(String ruta_imagen) {
// Objetos.
File imagenArchivo = new File(ruta_imagen);
Bitmap bitmap = null;
if (imagenArchivo.exists()) {
bitmap = BitmapFactory.decodeFile(imagenArchivo.getAbsolutePath());
}
return bitmap;
}
private Bitmap crearThumb(){
Bitmap bitmap = getBitmap(ruta_imagen);
BitmapFactory.Options opciones = new BitmapFactory.Options();
opciones.inJustDecodeBounds = true;
BitmapFactory.decodeFile(ruta_imagen, opciones);
int scaleW = opciones.outWidth / 854 + 1;
int scaleH = opciones.outHeight / 480 + 1;
int scale = Math.max(scaleW, scaleH);
opciones.inJustDecodeBounds = false;
opciones.inSampleSize = scale;
opciones.inSampleSize = scale;
bitmap = BitmapFactory.decodeFile(ruta_imagen, opciones);
return bitmap;
}
The error is because it just can't find the file or it doesn't exist:
You are not initializing the variable
ruta_imagen
so it cannot find a file.