java.lang.OutOfMemoryError: bitmap size exceeds VM budget?
<p>friends,</p>

<p>i am using following code to display bitmap on screen and having next and previous buttons to change images.</p>

<p>and getting out of memory error</p>

<p><strong>New Code</strong></p>

<pre><code>HttpGet httpRequest = null; 


                             try { 
                                     httpRequest = new HttpGet(mImage_URL[val]); 
                             } catch (Exception e) { 
                                 return 0;
                             } 


                             HttpClient httpclient = new DefaultHttpClient(); 
                             HttpResponse response = (HttpResponse) httpclient.execute(httpRequest); 

                             Bitmap bm;
                             HttpEntity entity = response.getEntity(); 
                             BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); 
                             InputStream is = bufHttpEntity.getContent(); 
                             try
                             {
                                 bm = BitmapFactory.decodeStream(is);
                                                                              }catch(Exception ex)
                             {
                             }
                             is.close(); 
</code></pre>

<p><strong>Old Code</strong></p>

<pre><code>URL aURL = new URL(mImage_URL[val]);  
                             URLConnection conn = aURL.openConnection(); 

                             conn.connect();  

InputStream is = null;
                             try
                             {
                                 is= conn.getInputStream();  
                             }catch(IOException e)
                             {
                             }
BufferedInputStream bis = new BufferedInputStream(is);  
 bm = BitmapFactory.decodeStream(bis);
 bis.close();  
 is.close(); 
 img.setImageBitmap(bm);
</code></pre>

<p>and it was giving me error decoder->decode return false.</p>

<p>on images of size bigger than 400kb.</p>

<p>so after googling i got new code as answer
the old code was not giving me out of memory error on those images but decoder->decode return false, so i choosed new code.</p>

<p>any one guide me what is the solution and which is the best approach to display live images?</p>
