Android 从服务器下载图像时出错
我从logcat得到这个错误 org.apache.http.NoHttpResponseException:目标服务器未能响应 原因可能是什么?Android 从服务器下载图像时出错,android,httpclient,Android,Httpclient,我从logcat得到这个错误 org.apache.http.NoHttpResponseException:目标服务器未能响应 原因可能是什么? 我的下载代码如下 HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = (HttpResponse)httpclient.execute(httpRequest); HttpEntity entity = response.getEntity(); Buff
我的下载代码如下
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);
调用以下方法并传入URL 公共位图DownloadFromUrl(String imageURL){//这是下载程序方法
Bitmap bm=null;
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;
}
NoHttpResponseException
意味着一件事:服务器关闭连接而不发送HTTP响应消息,这很可能是由于处理请求过程中遇到的异常情况。换句话说,这很可能是服务器端的错误。下载了两个图像,丢失了两个图像。对于丢失的图像,我得到了以下错误:SkImageDecoder::Factory返回Null我让您应该捕获此类异常,可能还有IOExceptions。对于此类错误,有3个选项,重试、取消和忽略。