I have 3 ImageViews and i am setting images randomly from URLs. I am getting java.lang.OutOfMemoryError. I am using following code to set image for an ImageView.
public void changeImages(){
try {
for(int i=0; i<items.size(); i++){
URL imageUrl = new URL(items.get(i).getImageUrl());
if(i == 0){
image1.setImageBitmap(BitmapFactory.decodeStream(imageUrl.openStream()));
}else if(i == 1){
image2.setImageBitmap(BitmapFactory.decodeStream(imageUrl.openStream()));
}else if(i == 2){
image3.setImageBitmap(BitmapFactory.decodeStream(imageUrl.openStream()));
}
}
} catch (Exception ex) {
System.out.println("Exception in parseResponse: "+ex);
}
}
image1, image2 and image3 are ImageViews. After changing images couple of times i get java.lang.OutOfMemoryError. Any idea how should i get rid of it? Thanks in advance.