我正在尝试从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
包含某种我不知道如何检索的值。
答案 0 :(得分:1)
试试这个:
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"));
}