How to handle out of memory error?
<p>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?</p>

<pre><code>  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;
</code></pre>

<p>Log cat:</p>

<pre><code>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)
</code></pre>
