Android:SingleClientConnManager 的使用无效:连接仍分配

发布于 2025-01-06 15:20:54 字数 1049 浏览 2 评论 0原文

可能的重复:
使用 HttpRequest.execute() 的异常:SingleClientConnManager 的使用无效:连接仍然分配

我在 Android 中工作。我创建了 HttpSingleton 类来在完整的应用程序中创建 HttpClient 的单个实例。

这是我使用此类的代码:-

HttpGet get = new HttpGet("url/dologin/savitagupta/savitagupta");
**HttpResponse rp = HttpSigleton.getInstance().execute(get);**          
if (rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
   // some code here
}

这是我的单个实例的类

public class HttpSigleton {
  private static HttpClient instance = null;
  protected HttpSigleton() {

  }
  public static HttpClient getInstance() {
    if(instance == null) {
       instance =new DefaultHttpClient();
    }
    return instance;
 }
}

然后发生的错误是:-

SingleClientConnManager:SingleClientConnManager 的使用无效:连接仍然分配。 确保在分配另一个连接之前释放该连接。 请告诉我我犯了什么错误。我真的需要你的帮助。 先感谢您。

Possible Duplicate:
Exception using HttpRequest.execute(): Invalid use of SingleClientConnManager: connection still allocated

I am working in Android. I created HttpSingleton class to create single intance of HttpClient in my complete application.

This is my code to use this class:-

HttpGet get = new HttpGet("url/dologin/savitagupta/savitagupta");
**HttpResponse rp = HttpSigleton.getInstance().execute(get);**          
if (rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
   // some code here
}

and this is my class for single instance

public class HttpSigleton {
  private static HttpClient instance = null;
  protected HttpSigleton() {

  }
  public static HttpClient getInstance() {
    if(instance == null) {
       instance =new DefaultHttpClient();
    }
    return instance;
 }
}

Then error is occurred is :-

SingleClientConnManager : Invalid use of SingleClientConnManager: connection still allocated.
Make sure to release the connection before allocating another one.
Please suggest me what mistake i have done. I really need your help.
Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空心空情空意 2025-01-13 15:20:54

对于 Android:

如果您对内容不感兴趣,摆脱连接并避免错误“连接仍然分配”的最便宜方法是:

httpResponse.getEntity().consumeContent();

请参阅 http://developer.android.com/reference/org/apache/http/HttpEntity.html#consumeContent()

For Android:

If you are not interested in the content, the cheapest way to get rid of your connection and avoid the error "connection still allocated" is:

httpResponse.getEntity().consumeContent();

See http://developer.android.com/reference/org/apache/http/HttpEntity.html#consumeContent()

风月客 2025-01-13 15:20:54

致电后:

HttpResponse rp = HttpSigleton.getInstance().execute(get);

请确保您拨打:

String html = EntityUtils.toString(rp.getEntity() /*, Encoding */);

EntityUtils.consume(rp.getEntity());

After calling:

HttpResponse rp = HttpSigleton.getInstance().execute(get);

Please make sure you make a call to either:

String html = EntityUtils.toString(rp.getEntity() /*, Encoding */);

or

EntityUtils.consume(rp.getEntity());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文