Error loading image path (Sqlite)

3

I select an image from the gallery and I save the path in Sqlite and up there everything is fine, the problem comes when trying to load the image, it shows ImageView empty and in Logcat I receive twice:

  

Unable to decode stream: java.io.FileNotFoundException:: open failed: ENOENT (No such file or directory)

Make it clear that in 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;
    }
    
asked by UserNameYo 01.07.2017 в 15:57
source

1 answer

1

The error is because you simply can not find the file or it does not exist:

  

Unable to decode stream: java.io.FileNotFoundException:: open failed:   ENOENT (No such file or directory)

You are not initializing variable ruta_imagen therefore you can not find a file.

    
answered by 01.07.2017 / 18:20
source