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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.