0

i am trying to display image from internet in my imageview.

which is raising following error any one guide me what mistake am i doing here

public Bitmap DisplayLiveImage(String ImageSrc) { Bitmap bm; try {

                             URL aURL = new URL(ImageSrc);  
                             URLConnection conn = aURL.openConnection(); 

                             conn.connect();  
                             InputStream is = null;
                             try
                             {
                                 is= conn.getInputStream();  
                             }catch(IOException e)
                             {
                                 return null;
                             }

                             BufferedInputStream bis = new BufferedInputStream(is);  

                             bm = BitmapFactory.decodeStream(bis);  
                             bis.close();  
                             is.close();  

                        } catch (IOException e) {  
                            return null;
                        }  

                        return  bm;

    }

logcat

11-12 21:45:22.509: ERROR/AndroidRuntime(7118): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
11-12 21:45:22.509: 

ERROR/AndroidRuntime(7118):     at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
11-12 21:45:22.509: 

ERROR/AndroidRuntime(7118):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:476)
11-12 21:45:22.509: 

ERROR/AndroidRuntime(7118):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:537)
11-12 21:45:22.509: 

ERROR/AndroidRuntime(7118):     at com.Finditnear.FindItNearActivityWithoutMenu.DisplayLiveImage

(FindItNearActivityWithoutMenu.java:149)
11-12 21:45:22.509: ERROR/AndroidRuntime(7118):     at com.Finditnear.ViewSingleImage$1.run

(ViewSingleImage.java:88)

any help would be appreciated.

DeRagan
  • 22,827
  • 6
  • 41
  • 50
UMAR-MOBITSOLUTIONS
  • 77,236
  • 95
  • 209
  • 278

1 Answers1

0

How large is the image you are trying to load? If it will result in a large bitmap you will run out of memory since Android only gives you a limited amount of memory for your app (16MB or 24MB on 2.2 devices I think). If it is a large image check out downsampling code on this post

Community
  • 1
  • 1
Ovi Tisler
  • 6,425
  • 3
  • 38
  • 63