Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

pavey nganpi
pavey nganpi
361 Points

how to query a ParseUser from a ParseObject

I am trying to create a follow/follower relationship where a i can get a list of followers of a user and a list of the people the user is following. So i created a Table called FollowRelation

ParseObject followRelation = new ParseObject(ParseConstants.KEY_FOLLOW_RELATION);
followRelation.put("from", ParseUser.getCurrentUser());
                followRelation.put("to", mUsers.get(position));
                followRelation.put("date",new Date().getTime());
                followRelation.saveInBackground(new SaveCallback() {
                    @Override
                    public void done(ParseException e) {
                        if(e == null){
                            Log.d("followRelation","success");
                        }
                        else{
                            Log.d("followRelation","error "+ e.getMessage());
                        }
                    }
                });

and below i do query to get all the people a certain user is following. but the usernames variable is null. I dont why. Someone pls help me figure this out thanks

 ParseQuery<ParseObject> query1 = ParseQuery.getQuery(ParseConstants.KEY_FOLLOW_RELATION);
        query1.whereEqualTo("from",ParseUser.getCurrentUser());
        query1.findInBackground(new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> followList, ParseException e) {
                if (e == null) {
                    Log.d("follow query","success");

                    mFollowFriends = followList;

                    String[] usernames = new String[mFollowFriends.size()];
                    int i = 0;
                    for (ParseObject user : mFollowFriends) {
                        //String test = user.getParseUser(ParseConstants.KEY_PARSE_USER_ID).toString();
                        String test1 = user.get(ParseConstants.KEY_USERNAME).toString();
                        String testt2 = user.get("from").toString();
                        usernames[i] = user.getString(ParseConstants.KEY_USERNAME);
                        Log.d("follow query usernames "," "+usernames[i] + " ");
                        i++;
                    }

//                    if (mGridView.getAdapter() == null) {
//                        UserAdapter adapter = new UserAdapter(getActivity(), mFriends);
//                        mGridView.setAdapter(adapter);
//                    } else {
//                        ((UserAdapter) mGridView.getAdapter()).refill(mFriends);
//                    }


                } else {
                    Log.d("follow query","error"+ e.getMessage());

//                    Log.e(TAG, e.getMessage().toString());
//                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
//                    builder.setMessage(e.getMessage());//creates a dialog with this message
//                    builder.setTitle(R.string.error_title);
//                    builder.setPositiveButton(android.R.string.ok, null);//creates a button to dismiss the dialog
//
//                    AlertDialog dialog = builder.create();//create a dialog
//                    dialog.show();//show the dialog

                }

            }
        });

    }