Android:SingleClientConnManager 的使用无效:连接仍分配
可能的重复:
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 Android:
如果您对内容不感兴趣,摆脱连接并避免错误“连接仍然分配”的最便宜方法是:
请参阅 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:
See http://developer.android.com/reference/org/apache/http/HttpEntity.html#consumeContent()
致电后:
请确保您拨打:
或
After calling:
Please make sure you make a call to either:
or