SkImageDecoder::Factory returned null

Android 开发中,使用HttpURLConnection加载网络图片的时候,

偶尔会出现:“SkImageDecoder::Factory returned null”错误!

代码如下:

 

HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); bitmap[i] = BitmapFactory.decodeStream(input); System.out.println("the bitmap is " + bitmap[i]);

 

输出:

SkImageDecoder::Factory returned null the bitmap is null

 

 

 

如果使用apache的HttpClient的话,就不会有问题了,

代码如下:

 

HttpGet httpRequest = new HttpGet(url); HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = (HttpResponse) httpclient.execute(httpRequest); HttpEntity entity = response.getEntity(); BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(entity); InputStream is = bufferedHttpEntity.getContent(); bitmap = BitmapFactory.decodeStream(is);

 

 

这里再一次证明了

 

apache的HttpClient比Java的HttpURLConnection强大

你可能感兴趣的:(java,apache,android,网络,null,input)