Android的HttpClient的异常控制问题(经理被关闭) [英] Android HttpClient Exception Control issue (Manager is shut down)

查看:154
本文介绍了Android的HttpClient的异常控制问题(经理被关闭)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的帖子一些字符串到我的服务器。结果
它使用的HttpClient发送DATAS。结果
所有功能都完美无1问题..结果

如果我的手机是在联网状态,那么结果
我点击提交按钮 - > DATAS可以在我的服务器上发送。 (实得非常好)结果

如果我的手机unnetworking(disconneing)状态(这意味着在不使用WiFi或3G ...)结果
我点击提交按钮 - >它显示出来错误对话框为你必须检查网络搜索

但问题是...结果
只要(约0.5〜1.5秒)我点击无线网络启用按钮,然后我点击提交按钮,结果
HttpClient的执行后显示出来的异常问题。(FC)结果
我可以控制异常的问题?
我想显示出来的错误对话框,但唯一的例外,我无法控制。结果
我认为无线过程中启用(或3G),执行一些事情发生的问题。结果

这是错误判决结果
02-06 00:48:41.250:E / AndroidRuntime(20183):java.lang.IllegalStateException:所致。管理器关闭

来源

 (...准备设置参数,可以和字符串datas..and等)            HttpPost httpPost =新HttpPost(URL);
            尝试{
                httpPost.setEntity(mpEntity);
                httpPost.addHeader(饼干,饼干);                //↓这是执行的问题。如何控制例外?
                HTT presponse响应= httpClient.execute(httpPost);                HttpEntity resEntity = response.getEntity();
                InputStream的内容= resEntity.getContent();
                返回的内容;
            }赶上(UnsupportedEncodingException五){
                e.printStackTrace();
            }赶上(ClientProtocolException E){
                e.printStackTrace();
            }赶上(IOException异常五){
                e.printStackTrace();
            }
            。httpClient.getConnectionManager()关机();
            返回null;
        }


解决方案

我觉得有问题的行

  httpClient.getConnectionManager()关机();

这是原来的Apache文档 ,没有更多的code(以及完整的堆栈跟踪)很难理解发生了什么事情。我认为这只是糟糕的API使用

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;
        }

解决方案

I think the problematic line is

        httpClient.getConnectionManager().shutdown();

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

这篇关于Android的HttpClient的异常控制问题(经理被关闭)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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