How to show a local folder image to an "ImageView"


I'm trying to show an image that is stored in the "drawable" folder and I'm using'setImageURI 'but for some reason I'm not sure the code is not working for me.

The information that I am uploading in the app is from a json file in which I have the name, location and address of the image.

to get the address of the image I'm using the method, which gives me a string with the address of the image.


student.getImage ();

Thanks to Julian I know that I can use: NuevaView.imagen.setImageResource (; to load the image, but it would always be the same image for all. There is some way to load the address of each image.

Try using setImageURI but I do not see anything in the palicacion, I leave blank the section of the image .. the json file has 20 members each with its name, location and a single image assigned to each one.

Something idea how I can solve this problem.

String img = estudiante.getImagen();
File imagenArchivo= new  File(img);

Here is the ImageView that I am using


and here the code to show the image

 if (vista== null) {
   vista= inflater.inflate(R.layout.lista, viewGroup, false);
   NuevaView= new NewView();
   NuevaView.nombre= (TextView) vista.findViewById(;
   NuevaView.locacion = (TextView) vista.findViewById(;
   NuevaView.imagen = (ImageView) vista.findViewById(;
        } else
   NewView = (NewView) view.getTag();;
        String img = estudiante.getImagen();
        File imagenArchivo= new  File(img);

            return vista;
        public class NuevaView{
            TextView nombre;
            TextView locacion;
            ImageView imagen;
asked by Pedro 29.06.2018 в 18:09

1 answer


The string you receive as an image of json is:


that refers to an image of name ci that is inside the folder /drawable , it is very important that this image or the images indicated by the feed as an image within "@drawable/" must exist in the project.

To load the image, it must be done in this way, first remember that to access a project resource in the /drawable directory, it can be done through this route:

"android.resource://<PAQUETE DE APLICACION>/drawable/"

Therefore this would be the appropriate way to load the image:

String img = estudiante.getImagen();
//Crea ruta de la imagen.
img = img.replace("@drawable/", "android.resource://"+ getPackageName() +"/drawable/");
//Obtiene la uri de la imagen.
Uri uriImagen = Uri.parse(img);
//Agrega imagen al ImageView.
answered by 29.06.2018 / 22:54