Android HttpClient异常控制问题(管理器关闭)
我的应用程序将一些字符串发送到我的服务器。
它使用HttpClient发送数据。
所有功能都很完美,没有 1 个问题..
如果我的手机处于联网状态,那么
我点击提交按钮->数据可以在我的服务器上发送。 (真的很好)
如果我的手机处于未联网(disconneing)状态(这意味着没有使用wifi或3g...)
我点击提交按钮->它显示错误对话框为“您必须检查网络”
但问题是...
一旦(大约0.5~1.5秒)我单击wifi启用按钮,然后单击提交按钮,
HttpClient执行后出现异常问题。(FC)
我可以控制异常问题吗? 我想显示错误对话框,但是,例外,我无法控制。
我认为在启用wifi(或3g)期间,执行过程中发生了问题。
这是错误语句
02-06 00:48:41.250:E / AndroidRuntime(20183):引起:java.lang.IllegalStateException:管理器已关闭。
来源
(...ready for setting params, and string datas..and so on)
HttpPost httpPost = new HttpPost(url);
try {
httpPost.setEntity(mpEntity);
httpPost.addHeader("cookie", cookie);
//↓This execute is problem. How can I control exception?
HttpResponse response = httpClient.execute(httpPost);
HttpEntity resEntity = response.getEntity();
InputStream content = resEntity.getContent();
return content;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
httpClient.getConnectionManager().shutdown();
return null;
}
My app posts some strings to my server.
It use HttpClient to send datas.
All functions are perfect without 1 problem..
If My phone is on networking state then
I click submit button -> Datas can be send on my server. (real very well)
If My phone is unnetworking(disconneing) state (it means not using wifi or 3g...)
I click submit button -> It showing up Error Dialog as 'You have to check network'
But Problem is...
As soon as(about in 0.5~1.5 seconds) I click wifi enable button then I click submit button,
The HttpClient post execution showing up exception problem.(FC)
Can I control the exception problem?
I want showing up error dialog but, The exception, I can't control.
I think during wifi is enabling (or 3g), the execution something happen problems.
This is error sentence
02-06 00:48:41.250: E/AndroidRuntime(20183): Caused by: java.lang.IllegalStateException: Manager is shut down.
The Source
(...ready for setting params, and string datas..and so on)
HttpPost httpPost = new HttpPost(url);
try {
httpPost.setEntity(mpEntity);
httpPost.addHeader("cookie", cookie);
//↓This execute is problem. How can I control exception?
HttpResponse response = httpClient.execute(httpPost);
HttpEntity resEntity = response.getEntity();
InputStream content = resEntity.getContent();
return content;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
httpClient.getConnectionManager().shutdown();
return null;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为有问题的行是
这是原始的 Apache 文档< /a>,如果没有更多代码(以及完整的堆栈跟踪),很难理解发生了什么。我认为这只是 API 使用不当
I think the problematic line is
This is the original Apache documentation, without more code (and the full stack trace) is difficult to understand what's going on. I think it's just bad API usage