1

I'm trying to get the value relatedGuild from ParseObject relationShipObject that has been sent to another method.

My code:

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"));
}

When i call Log.d in method getGuild i get a value equal to null. Am I trying to retrieve the value from row relatedGuild the wrong way? If yes, do you have any solution to the problem?

Update: When i change from getString to get("relatedGuild").toString(), i get a value that looks like this: com.parse.ParseObject@21u702b7. That means relationShipObjectcontains some kind of value i don't know how to retrieve.

2
  • That means relatedGuild is a ParseObject, which indicates that it is a pointer. So you can get the object from that pointer field by calling relationShipObject.getParseObject("relatedGuild"). Then what you want to do with it is up to you. Commented Nov 22, 2015 at 23:19
  • 1
    No, getParseObject("relatedGuild") does not fetch the object; only the pointer. To get the object, use include() in the query like I suggest in my answer, or call fetch() on the relatedGuild object before using it. Commented Nov 23, 2015 at 10:51

1 Answer 1

1

Try this:

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"));
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.