我有问题。我想使用PhP从我的mysql数据库中获取数据,但是我得到了错误:
org.json.JSONException:W / System.err的字符0处的输入结束:at org.json.JSONTokener.syntaxError(JSONTokener.java:450)W / System.err:
at org.json.JSONTokener.nextValue(JSONTokener.java:97)W / System.err:
在org.json.JSONObject。(JSONObject.java:156)W / System.err:
在org.json.JSONObject。(JSONObject.java:173)W / System.err:
在 neimantasjocius.com.justbeontop.LoginActivity.returnPoints(LoginActivity.java:123) W / System.err:at neimantasjocius.com.justbeontop.LoginActivity.access $ 100(LoginActivity.java:27) W / System.err:at neimantasjocius.com.justbeontop.LoginActivity $ AsyncDataClass.onPostExecute(LoginActivity.java:99) W / System.err:at neimantasjocius.com.justbeontop.LoginActivity $ AsyncDataClass.onPostExecute(LoginActivity.java:68) W / System.err:在android.os.AsyncTask.finish(AsyncTask.java:632) W / System.err:at android.os.AsyncTask.access $ 600(AsyncTask.java:177)W / System.err:
在 android.os.AsyncTask $ InternalHandler.handleMessage(AsyncTask.java:645) W / System.err:at android.os.Handler.dispatchMessage(Handler.java:102)W / System.err:
在android.os.Looper.loop(Looper.java:135)W / System.err:at android.app.ActivityThread.main(ActivityThread.java:5272) W / System.err:at java.lang.reflect.Method.invoke(Native Method) W / System.err:at java.lang.reflect.Method.invoke(Method.java:372) W / System.err:at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:909) W / System.err:at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704) W / ResourceType:获取资源值时没有包标识符 编号0x00000000 D / AndroidRuntime:关闭VM E / AndroidRuntime: 致命异常:主要流程:neimantasjocius.com.justbeontop,PID: 30041 android.content.res.Resources $ NotFoundException:字符串资源 android.content.res.Resources.getText的ID#0x0(Resources.java:275) 在android.widget.TextView.setText(TextView.java:4261)处 neimantasjocius.com.justbeontop.LoginActivity $ AsyncDataClass.onPostExecute(LoginActivity.java:101) 在 neimantasjocius.com.justbeontop.LoginActivity $ AsyncDataClass.onPostExecute(LoginActivity.java:68) 在android.os.AsyncTask.finish(AsyncTask.java:632)at android.os.AsyncTask.access $ 600(AsyncTask.java:177)at android.os.AsyncTask $ InternalHandler.handleMessage(AsyncTask.java:645) 在android.os.Handler.dispatchMessage(Handler.java:102)at android.os.Looper.loop(Looper.java:135)at android.app.ActivityThread.main(ActivityThread.java:5272)at java.lang.reflect.Method.invoke(Native Method)at java.lang.reflect.Method.invoke(Method.java:372)at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:909) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)
以下是我使用的代码:我标记了给出错误的数字行。
private final String serverUrl = "http://*******.***"; // <---- 27
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Intent intent = getIntent();
Bundle intentBundle = intent.getExtras();
String loggedUser = intentBundle.getString("USERNAME");
loggedUser = capitalizeFirstCharacter(loggedUser);
TextView loginUsername = (TextView) findViewById(R.id.login_user);
loginUsername.setText(loggedUser);
AsyncDataClass asyncRequestObject = new AsyncDataClass();
asyncRequestObject.execute(serverUrl);
}
private class AsyncDataClass extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);
HttpConnectionParams.setSoTimeout(httpParameters, 5000);
HttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpPost httpPost = new HttpPost(params[0]);
String PointsString = "";
try {
HttpResponse response = httpClient.execute(httpPost);
PointsString = inputStreamToString(response.getEntity().getContent()).toString();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return PointsString;
} // <---- 68
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
int points = returnPoints(result);
TextView pointsText = (TextView)findViewById(R.id.pointsText);
pointsText.setText(points);
}
private StringBuilder inputStreamToString(InputStream is) {
String rLine = "";
StringBuilder answer = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
try {
while ((rLine = br.readLine()) != null) {
answer.append(rLine);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return answer;
}
}
private int returnPoints(String result){
JSONObject resultObject = null;
int returnedPoints = 0;
try { // <----- 99
resultObject = new JSONObject(result);
returnedPoints = resultObject.getInt("points"); // <--- 101
} catch (JSONException e) {
e.printStackTrace();
}
return returnedPoints;
}
private String capitalizeFirstCharacter(String textInput){
String input = textInput.toLowerCase();
String output = input.toUpperCase();
return output;
} // <-- Actually its 113 but error is given at 123