2011-05-02 54 views
1

當我嘗試在HttpResponse上使用BufferedReader時,我收到「SocketException:Bad file number」。 基本上我試着解析我的服務器響應。奇怪的是,它只發生在我的LG 2x(Android 2.2.2)上,我沒有在Android模擬器(Google 2.2)和HTC(2.2)上看到這個錯誤。SocketException:錯誤的文件號。我該如何解決它?

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

在代碼中是否有這樣的內容?

httpClient.getConnectionManager().shutdown(); 

就我而言,我不得不關閉我的ConnectionManager 得到響應

相關問題