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 Build a Self-Destructing Message Android App Relating Users in Parse.com Adding Checkmarks When the List is Loaded

Alex Park
Alex Park
7,567 Points

Getting errors with .findinBackground - Suddenly it doesn't work

EditFriendsActivity and here is the code.

private void addFriendCheckmarks() {
        mFriendsRelation.getQuery().findInBackground(new FindCallback<ParseUser>() {
            @Override
            public void done(List<ParseUser> friends, ParseException e) {
                if (e == null) {
                    // list returned - look for a match
                    for (int i = 0; i < mUsers.size(); i++) {
                        ParseUser user = mUsers.get(i);

                        for (ParseUser friend : friends) {
                            if (friend.getObjectId().equals(user.getObjectId())) {
                                getListView().setItemChecked(i, true);
                            }
                        }
                    }
                }
                else {
                    Log.e(TAG, e.getMessage());
                }
            }
        });
    }```

This is my code and i am keep getting red lines on the .findInBackground(new ~ <- this part
I even imported the project file (this worked)
and copy & pasted to my code (same code, but this doesn't)
But mine is keep getting red lines

It says
```The method findInBackground(FindCallback<ParseObject>) in the type ParseQuery<ParseObject> is not applicable for the arguments (new FindCallback<ParseUser>(){})```

I've restarted eclipse
restarted the computer
cleaned projects

but i'm keep getting an error
can anyone help me please? :/

1 Answer

You need to make two small changes to your method by declaring the generic type "ParseUser" in two places:

private void addFriendCheckmarks() {
        //HERE                                             !!!!!!!!!!!!!!
        mFriendsRelation.getQuery().findInBackground(new FindCallback<ParseUser>() { 
            @Override
             //AND HERE      !!!!!!!!!!!!!!
            public void done(List<ParseUser> friends, ParseException e) {
                if(e == null){
                    //list returned look for match
                    for(int i = 0; i < mUsers.size(); i++){
                        ParseUser user = mUsers.get(i);

                        for(ParseUser friend : friends){
                            if(friend.getObjectId().equals(user.getObjectId())){
                                getListView().setItemChecked(i, true);
                            }
                        }
                    }
                }
                else{
                    Log.e(TAG, e.getMessage());
                }
            }
        });
    }