*EDIT:
So I've asked the PHP Guy, and yes he forgot to write the "fullname"
string in his code. Sorry for my mistake.
I'm new in Java Android, so a lil bit confuse about this code. What I'm trying to do is get the value, but it always whot this error in Android Studio :
W/System.err: org.json.JSONException: No value for fullname
W/System.err: at org.json.JSONObject.get(JSONObject.java:355)
W/System.err: at org.json.JSONObject.getString(JSONObject.java:515)
W/System.err: at com.skafen.bayarin.ServerRequests$fetchUserDataAsyncTask.doInBackground(ServerRequests.java:130)
W/System.err: at com.skafen.bayarin.ServerRequests$fetchUserDataAsyncTask.doInBackground(ServerRequests.java:93)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err: at java.lang.Thread.run(Thread.java:841)
And the java is :
public class fetchUserDataAsyncTask extends AsyncTask<Void, Void, User> { //line #93
User user;
GetUserCallback userCallback;
public fetchUserDataAsyncTask(User user, GetUserCallback userCallback) {
this.user = user;
this.userCallback = userCallback;
}
@Override
protected User doInBackground(Void... params) {
ArrayList<NameValuePair> dataToSend = new ArrayList<>();
dataToSend.add(new BasicNameValuePair("username", user.username));
dataToSend.add(new BasicNameValuePair("password", user.password));
HttpParams httpRequestParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpRequestParams, CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpRequestParams, CONNECTION_TIMEOUT);
HttpClient client = new DefaultHttpClient(httpRequestParams);
HttpPost post = new HttpPost(SERVER_ADDRESS + "FetchUserData.php");
User returnedUser = null;
try {
post.setEntity(new UrlEncodedFormEntity(dataToSend));
HttpResponse httpResponse = client.execute(post);
HttpEntity entity = httpResponse.getEntity();
String result = EntityUtils.toString(entity);
JSONObject jObject = new JSONObject(result);
if (jObject.length() == 0 ){
returnedUser = null;
}else {
String fullname = jObject.getString("fullname"); //line #130
int birthday = jObject.getInt("birthday");
String email = jObject.getString("email");
returnedUser = new User(fullname, birthday, email, user.username, user.password);
}
}catch (Exception e){
e.printStackTrace();
}
return returnedUser;
}
@Override
protected void onPostExecute(User returnedUser) {
progressDialog.dismiss();
userCallback.done(returnedUser);
super.onPostExecute(returnedUser);
}
}
Thanks for the attention, and sorry if I post a new thread with same topic because I'm new here.
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…