SocketException:错误的文件号。我该如何解决?

时间:2011-05-02 13:21:19

标签: android

每当我尝试在BufferedReader上使用HttpResponse时,我都会收到“SocketException:Bad file number”。 基本上我尝试从服务器解析我的响应。奇怪的是,它只发生在我的LG 2x(Android 2.2.2)上,我在Android模拟器(谷歌2.2)和HTC(2.2)上没有出现这个错误。

In this thread someone explained why the error occurs.但为什么问题只发生在LG手机上,更重要的是,我该如何解决呢?

HttpResponse response = JSONHelper.postJSONObject(WebSMSActivity.this, Consts
                                                .api_url("settings"), json,
                                                "Registration");

// Read the response for the JSON reply
try {
    BufferedReader in = new BufferedReader(
                new InputStreamReader(response.getEntity().getContent(), "UTF-8"), 8 * 1024);


    // Read every line (should actually only be
    // one
    StringBuilder builder = new StringBuilder();
    for (String line = null; (line = in.readLine()) != null;) {
        builder.append(line).append("\n");
        Log.w(Consts.LOG_TAG_SERVICE, line);
    }
    String textResponse = builder.toString(); } catch (IOException ex) {}

1 个答案:

答案 0 :(得分:1)

你的代码中有这样的东西吗?

   httpClient.getConnectionManager().shutdown();

在我的情况下,我不得不关闭我的connectionManager AFTER 获取回复