how to handle out of memory error?
        Posted  
        
            by UMMA
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by UMMA
        
        
        
        Published on 2010-06-14T06:03:07Z
        Indexed on 
            2010/06/14
            6:52 UTC
        
        
        Read the original article
        Hit count: 362
        
android
dear friends,
i am using following code to display bitmap in my imageview. when i try to load image of size for example bigger than 1.5MB it give me error any one suggest me solution?
  try {  
                         URL aURL = new URL(myRemoteImages[val]);  
                         URLConnection conn = aURL.openConnection(); 
                         conn.connect();  
                         InputStream is = null;
                         try
                         {
                             is= conn.getInputStream();  
                         }catch(IOException e)
                         {
                             return 0;
                         }
                         int a=  conn.getConnectTimeout();
                         BufferedInputStream bis = new BufferedInputStream(is);  
                         Bitmap bm;
                         try
                         {
                             bm = BitmapFactory.decodeStream(bis);
                         }catch(Exception ex)
                         {
                             bis.close(); 
                             is.close();  
                             return 0; 
                         }
                         bis.close();  
                         is.close();  
                         img.setImageBitmap(bm);
                    } catch (IOException e) {  
                        return 0;
                    }  
                    return 1;
Log cat
06-14 12:03:11.701: ERROR/AndroidRuntime(443): Uncaught handler: thread main exiting due to uncaught exception 06-14 12:03:11.861: ERROR/AndroidRuntime(443): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 06-14 12:03:11.861: ERROR/AndroidRuntime(443): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
© Stack Overflow or respective owner