내 앱에 어떤 문제가 있는지 알 수 없습니다. 현재, 나는 레스토랑 찾기 응용 프로그램을 개발 중입니다. 데이터베이스의 경우 PHP와 mySQL을 사용하고 있습니다. 인터페이스에서 삽입 한 데이터는 데이터베이스 (localhost)에 표시됩니다. 그러나 응용 프로그램은 "응용 프로그램 RestFinder (process.com.example.restaurantfinder)가 예기치 않게 중지되었습니다. 다시 시도하십시오."라는 메시지를 계속 표시합니다. 그리고 나서 추락했습니다. 나는 로그 파일을 검사 할 때데이터를 파싱하는 중 오류가 발생했습니다. org.json.JSONException : java.lang.String 유형의 db_connect.php 값을 JSONObject로 변환 할 수 없습니다.
, 첫 번째 로그 파일은 다음과 같습니다
는Error parsing data org.json.JSONException: Value db_connect.php of type java.lang.String cannot be converted to JSONObject
은 누군가가 나에게 이것에 대한 해결책을 줄 수 있습니까?
이들은 오류를 일으킨 것으로 의심되는 JSONParser.java의 코드입니다.
public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) {
// Making HTTP request
try {
// check for request method
if (method == "POST") {
// request method is POST
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} else if(method == "GET") {
// request method is GET
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
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();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json.substring(6));
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
오류의 원인이되는 코드를 알려 주시기 바랍니다. 입력은 –
...입니다. –
매트 볼 : 스냅 샷을 의미합니까? – Syah