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...
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.
}
}
});
İf you want to get current user this may be helpful;
String currentUser = ParseUser.getCurrentUser().getUsername();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With