how to find a user in a ParseUser object
11,888
Solution 1
Parse treats User objects separate 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 the Parse example with your 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.
}
}
});
Solution 2
İf you want to get current user this may be helpful;
String currentUser = ParseUser.getCurrentUser().getUsername();
Author by
James
Updated on June 20, 2022Comments
-
James almost 2 years
Hi I was wondering why this code does not work. I am trying to query a ParseUser's username field to find a certain user but it keeps saying that it cant find it.
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 couldnt return it in the method...