Android : Getting this error while downloading image from remote server: SkImageDecoder::Factory returned null
<p>I am trying to download images from a remote server, the number of images downloaded is 30. The code i am using to download image is as below. Some images download successfully and some images don't download and raises the above exception. What might be the problem.</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) {
        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>
