我正在尝试从已发送到另一方法的relatedGuild
中获取值ParseObject relationShipObject
。
我的代码:
private void getRelation(){
Log.i("Status:", "Retrieving current user...");
//Retrieve the current logged in user
ParseUser currentUser = ParseUser.getCurrentUser();
Log.i("Status:", "Retrieving relationship...");
//Retrieve the relationship object for currentUser
ParseQuery<ParseObject> relationQuery = ParseQuery.getQuery("relation");
query.whereEqualTo("relatedUser", currentUser);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> relationShip, ParseException e) {
if (e == null) {
for (ParseObject relationShipObject : relationShip) {
// This does not require a network access.
relationshipObject.get("relatedGuild");
getGuild(relationShipObject);
}
} else {
Log.d("relation", "Error: " + e.getMessage());
}
}
});
}
private void getGuild(ParseObject relationShipObject){
Log.d("relation", "relationShipObject:" + relationShipObject.getString("relatedGuild"));
}
当我在方法
Log.d
中调用getGuild
时,我得到的值等于null
。我是否尝试以错误的方式从行relatedGuild
检索值?如果是,您有解决问题的办法吗?更新:
当我从
getString
更改为get("relatedGuild").toString()
时,我得到的值看起来像这样:com.parse.ParseObject@21u702b7
。这意味着relationShipObject
包含某种我不知道如何获取的值。 最佳答案
尝试这个:
private void getRelation(){
Log.i("Status:", "Retrieving current user...");
//Retrieve the current logged in user
ParseUser currentUser = ParseUser.getCurrentUser();
Log.i("Status:", "Retrieving relationship...");
//Retrieve the relationship object for currentUser
ParseQuery<ParseObject> relationQuery = ParseQuery.getQuery("relation");
query.whereEqualTo("relatedUser", currentUser);
query.include("relatedGuild"); // <-THIS INCLUDES THE OBJECT BEHIND THE POINTER
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> relationShip, ParseException e) {
if (e == null) {
for (ParseObject relationShipObject : relationShip) {
// This does not require a network access.
relationshipObject.get("relatedGuild");
getGuild(relationShipObject);
}
} else {
Log.d("relation", "Error: " + e.getMessage());
}
}
});
}
private void getGuild(ParseObject relationShipObject){
Log.d("relation", "relationShipObject:" + relationShipObject.getString("relatedGuild"));
}