Android : Big error while downloading images
<p>I have tried three ways of downloading images. All suggest by members of Stackoverflow .
All the three methods fail to download all the images from the server. Few are downloaded and few are not. </p>

<p>I noticed a thing that each of the method fail to download image from particular position.
That is method 3 always fails to download the first three images. I changed the images but even then , the first three images are not downloaded.</p>

<p>Method 1:</p>

<pre><code> public Bitmap downloadFromUrl( String imageurl )
   {
       Bitmap bm=null;
       String imageUrl = imageurl;
       try {
               URL url = new URL(imageUrl); //you can write here any link

              URLConnection ucon = url.openConnection();


             InputStream is = ucon.getInputStream();
              BufferedInputStream bis = new BufferedInputStream(is);


               ByteArrayBuffer baf = new ByteArrayBuffer(50);
              int current = 0;
              while ((current = bis.read()) != -1) {
                       baf.append((byte) current);
              }

             bm= BitmapFactory.decodeByteArray(baf.toByteArray(), 0, baf.toByteArray().length);


     } catch (IOException e) {
               Log.d("ImageManager", "Error: " + e);
     }
       return bm;

   }
</code></pre>

<p>Here the error i get for missed images is :SKIimagedecoder , the factory returned null.</p>

<p>Method: 2</p>

<pre><code> public static Bitmap loadBitmap(String url) 
   {
       Bitmap bitmap = null;
       InputStream in = null;
       BufferedOutputStream out = null;

       try {
           in = new BufferedInputStream(new URL(url).openStream(), 4*1024);

           final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
           out = new BufferedOutputStream(dataStream,  4 * 1024);

           int byte_;
           while ((byte_ = in.read()) != -1)
               out.write(byte_);
           out.flush();

           final byte[] data = dataStream.toByteArray();
           BitmapFactory.Options options = new BitmapFactory.Options();
           //options.inSampleSize = 1;

           bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,options);
       } catch (IOException e) {
           System.out.println(e);
           Log.e("","Could not load Bitmap from: " + url);
       } finally {
           try{
               in.close();
               out.close();
           }catch( IOException e )
           {
               System.out.println(e);
           }
       }

       return bitmap;
   }
</code></pre>

<p>The error i get here is same as above.</p>

<p>Method 3:</p>

<pre><code>private Bitmap downloadFile(String fileUrl){
    URL bitmapUrl =null;  
    Bitmap bmImg = null;
    try {
        bitmapUrl= new URL(fileUrl);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    HttpGet httpRequest = null;

    try {
            httpRequest = new HttpGet(bitmapUrl.toURI());
    } catch (URISyntaxException e) {
            e.printStackTrace();
    }

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

        HttpEntity entity = response.getEntity();
        BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
        InputStream instream = bufHttpEntity.getContent();
        bmImg = BitmapFactory.decodeStream(instream);
    } catch (Exception e) {
            System.out.println(e);
    }
    return bmImg;
}
</code></pre>

<p>The error i get here is : org.apache.http.NoHttpResponseException: The target server failed to respond.   </p>

<p>please help. It is the only thing stopping me from completing the project.</p>
