在我的代码的这一部分中,底部的return语句返回的是ReturUser = null而不是returnUser = new User(user.username,name,sex,age,user.password);
有关为何发生这种情况的任何想法?不应该第二个returnUser = new用户覆盖returnedUser = null?
我在调试模式下运行它并且它正在命中else语句并且返回的winsUser正在更新为正确的信息,但是当它返回到返回的returnUser语句时,它返回returnUser = null。
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){
user = null;
}else{
String name = jObject.getString("name");
String sex = jObject.getString("sex");
int age = jObject.getInt("age");
returnedUser = new User(user.username, name, sex, age, user.password);
}
} catch (Exception e) {
e.printStackTrace();
}
return returnedUser;
}
public class User {
String username, name, sex, password;
int age;
public User (String username, String name, String sex, int age,
String password){
this.username = username;
this.name = name;
this.sex = sex;
this.age = age;
this.password = password;
}
public User(String username, String password) {
this.username = username;
this.password = password;
this.name = "";
this.sex = "N/A";
this.age = -1;
}
}