SingleClientConnManager

SingleClientConnManager

本文介绍了安卓:使用无效SingleClientConnManager的:连接仍然分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/4612573/exception-using-htt$p$pquest-execute-invalid-use-of-singleclientconnmanager-c">Exception使用的Htt prequest.execute():使用无效SingleClientConnManager的:连接仍然分配

我在Android的工作。我创建HttpSingleton类在我的完整的应用程序创建一个HttpClient单intance。

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

这是我的code使用这个类: -

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:使用无效SingleClientConnManager的:还是分配的连接。 确保释放分配才能再次连接。请建议我有什么错误,我所做的一切。我真的需要你的帮助。谢谢你在前进。

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.

推荐答案

调用后:

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

请确保您拨打一个电话要么:

Please make sure you make a call to either:

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

EntityUtils.consume(rp.getEntity());

这篇关于安卓:使用无效SingleClientConnManager的:连接仍然分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 01:08