SocketException: Bad file number. How can I solve it?
I get a "SocketException: Bad file number" whenever I try to use a BufferedReader
on a HttpResponse
.
Basically I try to parse my response开发者_运维问答 from the server. The strange thing is, that it only happens on my LG 2x (Android 2.2.2), I don't get this error on the Android Emulator (Google 2.2) and on a HTC (2.2).
In this thread someone explained why the error occurs. But why is the problem only happening on the LG phone, and more importantly, how can I solve it?
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) {}
Do you have something like this in your code ?
httpClient.getConnectionManager().shutdown();
In my case, I had to shutdown my connectionManager AFTER getting the response
精彩评论