How to find a user in a ParseUser object

Hi, I was wondering why this code is not working. I am trying to query the ParseUser username field to find a specific user, but he continues to say that he cannot find him.

private void findUserName(String user) { // query the User database to find the passed in user ParseQuery query = ParseUser.getQuery(); query.whereEqualTo("username", user); query.findInBackground(new FindCallback() { @Override public void done(List<ParseObject> objects, ParseException e) { foundUser = (objects.size() != 0); } }); } 

Here is my method that calls it

 if (!foundUser) { errorMessage.setText("Invalid user name"); } 

foundUser is a field because I could not return it in a method ...

+4
source share
2 answers

Parse treats user objects separately from Parse objects. You should use List<ParseUser> instead of List<ParseObject> . The Parse Android Guide provides an example https://parse.com/docs/android_guide#users-querying . Here is an example of Parse with a where clause.

 ParseQuery<ParseUser> query = ParseUser.getQuery(); query.whereEqualTo("username", user); query.findInBackground(new FindCallback<ParseUser>() { public void done(List<ParseUser> objects, ParseException e) { if (e == null) { // The query was successful. } else { // Something went wrong. } } }); 
+15
source

If you want to get the current user, this may be useful;

 String currentUser = ParseUser.getCurrentUser().getUsername(); 
+1
source

Source: https://habr.com/ru/post/1481522/