SkImageDecoder::Factory returned null

本文对比了Android开发中使用HttpURLConnection和Apache HttpClient加载网络图片时遇到的‘SkImageDecoder::Factoryreturnednull’错误问题,并通过代码示例展示了如何使用HttpClient解决此问题。

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

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

代码如下:

<wbr></wbr>

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

<wbr></wbr>

输出:

SkImageDecoder::Factory returned null the bitmap is null

<wbr></wbr>

<wbr></wbr>

<wbr></wbr>

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

代码如下:

<wbr></wbr>

HttpGethttpRequest = newHttpGet(url); HttpClienthttpclient = newDefaultHttpClient(); HttpResponseresponse = (HttpResponse) httpclient.execute(httpRequest); HttpEntityentity = response.getEntity(); BufferedHttpEntitybufferedHttpEntity = newBufferedHttpEntity(entity); InputStreamis = bufferedHttpEntity.getContent(); bitmap =BitmapFactory.decodeStream(is);

<wbr></wbr>

<wbr></wbr>

这里再一次证明了

<wbr></wbr>

apache的HttpClient比Java的HttpURLConnection强大

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值