1
votes

I am having some trouble getting some data from my Parse table/object with a query. I am trying to simply make a query which looks for the current Parse User's objectID in the "sender" column. When that result is returned, I want to extract the receiver's objectID from the "receiver" column associated with the user that I searched for. I keep getting 0 results, even though I know the data is there. Here is my code:

 private List<String> potentialRelationQuery() {
    mPotentialRelations = new ArrayList<>();
    String currentUserId = mCurrentUser.getObjectId();
    ParseQuery<ParseObject> query3 = ParseQuery.getQuery("PotentialRelation");
    query3.whereEqualTo("sender", currentUserId);
    query3.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> parseObjects, ParseException e) {
            if (e == null) {
                if (parseObjects.size() > 0) {                       
                    for (int i = 0; i < parseObjects.size(); i++) {
                        ParseUser receiver = (ParseUser) parseObjects.get(i).get("receiver");
                        String receiverId = receiver.getObjectId();
                        mPotentialRelations.add(receiverId);
                    }
                }
            } else {
                Log.d("MyApp", "No matching objects returned from request");
            }
        }
    });
    return mPotentialRelations;
}
1
I made some changes to the code and changed them above. I couldn't figure out how to post new code in the comment box below...I call this method from another part of the code and want to return the array list called mPotentialRelations. It is still returning nothing, as the Log message returns "No matching objects...." although the data is still there... Help! - Wayne Johnson
I was able to create a log of an error message and got the following message: error = pointer field "sender" needs a pointer value. Looks like maybe a type mismatch? - Wayne Johnson
Problem solved... Instead of passing the mCurrentUser.getObjectId(), which is a String, I simply changed the query to query3.whereEqualTo("sender", mCurrentUser); which is a User object. Query works perfectly now - Wayne Johnson

1 Answers

0
votes

Since findInBackground is an asynchronous call to Parse isn't it possible that mPotentialRelations returns empty because the findInBackground query hasn't yet completed before the potentialRelationQuery method returns? I know I've had issues with this. Since you can't return data from an inner class (i.e. in the done method of FindCallback), writing this kind of query method has never really worked consistently for me.