Error showing image on Android

1

Android is marking this error, but I really do not have the slightest idea why it is doing my process correctly and it shows me the image:

  

E / BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: http: /www.paisajesbonitos.org/wp-content/uploads/2016/04/paisajes-de-chile-patagonia-chile-paisajes-bonitos -beautiful-2.jpg: open failed: ENOENT (No such file or directory)

     

I / System.out: resolveUri failed on bad bitmap uri: link

     

IndexActivity.java

ArrayList<String> strings = new ArrayList<String>();
    if (checkIn.getImages().size() > 0) {//valido de que existan imagenes
        for (ImageData object: checkIn.getImages()) {
            strings.add(object.getPath());//al ArrayList le agrego los Bitmaps
        }//for
        gridView.setAdapter(new ImageAdapter(this, strings));//seteo las imagenes al gridView
    }//./if
  

InameAdapter.java

public class ImageAdapter extends ArrayAdapter {

private Context mContext;
private ArrayList<String> imagesList;

public ImageAdapter(Context context, ArrayList<String> imagesList){
    super(context, R.layout.activity_index, imagesList);//recibe como parametros el Contexto y un ArrayList de Bitmaps
    this.mContext = context;//se asgina valores
    this.imagesList = imagesList;//se asgina valores
}//./constructor

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView = new ImageView(mContext);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setLayoutParams(new GridView.LayoutParams(150, 150));

    for (int i = 0; i < imagesList.size(); i++) {
        Uri myUri = Uri.parse(imagesList.get(i));

        if (imagesList.size() > 0) {
            imageView.setImageURI(myUri);
        }
    }

    Glide.with(mContext).load(imagesList.get(position)).into(imageView);

    return imageView;
}

} //./ class

    
asked by Javier fr 23.12.2016 в 17:17
source

1 answer

2

The error is FileNotFoundException :

  

Unable to decode stream: java.io.FileNotFoundException:   http: /www.paisajesbonitos.org/wp-content/uploads/2016/04/paisajes-de-chile-patagonia-chile-paisajes-bonitos-hermosos-2.jpg

maybe if you upload the file in a browser the file exists but it can be 2 things, your application when loading the url is offline, or the server is not responding correctly when trying to deliver the image, in a few words the Resource is not found.

But you also have this error:

  

resolveUri failed on bad bitmap uri:

This error could be causing the previous, what I notice is that you are loading in the same%% of all the images! that contains the ArrayList mdiante ImageView , at this point you should only load one defined by setImageURI() :

  imageView.setImageURI(myUri);

But after loading the image, you also do it again with position :

 Glide.with(mContext).load(imagesList.get(position)).into(imageView);

The Glide you have to load the image is not necessary since the required image is obtained by for within the position that contains the images and you are loading it with ArrayList within Glide :

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView = new ImageView(mContext);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setLayoutParams(new GridView.LayoutParams(150, 150));

   /* for (int i = 0; i < imagesList.size(); i++) {
        Uri myUri = Uri.parse(imagesList.get(i));

        if (imagesList.size() > 0) {
            imageView.setImageURI(myUri);
        }
    }*/

    Glide.with(mContext).load(imagesList.get(position)).into(imageView);

    return imageView;
}

If you do not want to use Glide this would be the way to load the image (s):

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView = new ImageView(mContext);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setLayoutParams(new GridView.LayoutParams(150, 150));

    Uri myUri = Uri.parse(imagesList.get(position));
    imageView.setImageURI(myUri);

   /* for (int i = 0; i < imagesList.size(); i++) {
        Uri myUri = Uri.parse(imagesList.get(i));

        if (imagesList.size() > 0) {
            imageView.setImageURI(myUri);
        }
    }    
    Glide.with(mContext).load(imagesList.get(position)).into(imageView);
    */

    return imageView;
}
  

I did it this way

    @Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView = new ImageView(mContext);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setLayoutParams(new GridView.LayoutParams(150, 150));

    if (imagesList.size() > 0) {
        imageView.setImageBitmap(imagesList.get(position));
    }
    return imageView;
}

} //./ class

    
answered by 23.12.2016 в 19:25