URL에서 Json
개체를 반환하는이 코드가 있습니다. froyo
에서 제대로 작동하지만 동일한 코드가 Jelly Beans
에서 작동하지 않습니다.코드가 Jelly Beans에서 작동하지 않습니다.
내 코드에 문제가 있습니까?
것은 제발 도와주세요, 여기에 내 코드
public static JSONObject getJSONfromURL(String url) {
// initialize
InputStream is = null;
String result = "";
JSONObject jArray = null;
// http post
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
}
// convert response to string
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jArray = new JSONObject(result);
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
return jArray;
}
여기에 당신은 메인 스레드의 네트워크 연결을 설정하려고
11-01 11:01:48.437: E/log_tag(1044): Error in http connection android.os.NetworkOnMainThreadException 11-01 11:01:48.437: E/log_tag(1044): Error converting result java.lang.NullPointerException 11-01 11:01:48.437: E/log_tag(1044): Error parsing data org.json.JSONException: End of input at character 0 of
와 함께 갈 수있는 오류가 ? 그렇다면 게시하십시오. 네, 네트워크 관련 작업을 수행하고 있으므로 메인 스레드에서이 작업을 수행하지 않도록하십시오. [this] (http://android-developers.blogspot.in/2009/05/painless-threading.html) – juned
무엇을합니까? "일하지 않는다"는 뜻입니까? –
정확히 어떤 문제가 있는지 정확히 어떤 오류가 있는지 여부를 logcat 참조하십시오 ?? – Ravi