从URL SingleClientConnManager问题的Andr​​oid获取图像 [英] Android get image from url SingleClientConnManager problem

查看:155
本文介绍了从URL SingleClientConnManager问题的Andr​​oid获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下code获得标志的图像,并将其保存在数据库中。

I am using following code to get the images of a logo and save it in the database.

DefaultHttpClient mHttpClient = new DefaultHttpClient();
HttpGet mHttpGet;
HttpResponse mHttpResponse;
HttpEntity entity;


for (int reportsCount = 0; reportsCount < reportsArr.length; reportsCount++) {



  //Make a request to get our image
  mHttpGet = new HttpGet(reportsArr[reportsCount][1]);
  byte[] categoryLogoArr = null; 
  try {
    mHttpResponse = mHttpClient.execute(mHttpGet);

    if (mHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {


       entity = mHttpResponse.getEntity();

       logoArr= EntityUtils.toByteArray(entity);

    }
   } catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (IOException e) {
   // TODO Auto-generated catch block
    e.printStackTrace();
   }

   long categoryID = dataHelper.addCategory(reportsArr[reportsCount][0], categoryLogoArr);
}

第一个图像添加完美,但它不能正常工作,并给予下列警告。在其他情况下

The first image added perfectly, but rest of the cases it is not working and giving the following warning.

WARN/SingleClientConnManager(2389): Invalid use of SingleClientConnManager: connection still allocated.

在我的code是什么问题?要改变什么解决呢?

What is problem in my code? What to change to solve it?

推荐答案

您需要消耗的内容之前,你可以重复使用的连接。这可能是<一个重复href=\"http://stackoverflow.com/questions/4612573/exception-using-htt$p$pquest-execute-invalid-use-of-singleclientconnmanager-co\">Exception使用的Htt prequest.execute():使用无效的SingleClientConnManager:连接仍然分配

You need to consume the content before you can reuse the connection. This may be a duplicate of Exception using HttpRequest.execute(): Invalid use of SingleClientConnManager: connection still allocated.

我认为你需要消耗的内容即使响应code不是HttpStatus.SC_OK,并在异常处理。

I think that you need to consume the content even if the response code is not HttpStatus.SC_OK, and in your exception handlers.

这篇关于从URL SingleClientConnManager问题的Andr​​oid获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆