问题描述
您好我想知道为什么code不起作用。我想查询ParseUser的用户名现场找到一个特定的用户,但它口口声声说,它不能找到它。
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);
}
});
}
下面是我的方法调用它
if (!foundUser) {
errorMessage.setText("Invalid user name");
}
foundUser是一个字段,因为我不可能在该方法返回它...
foundUser is a field because I couldnt return it in the method...
推荐答案
解析会将用户从解析对象的对象区分开来。您应该使用名单,其中,ParseUser&GT;
,而不是的名单,其中,的parseObject&GT;
。解析Android的指南提供了一个例子https://parse.com/docs/android_guide#users-querying.下面是解析例如你的where子句。
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.
}
}
});
这篇关于如何找到在一个ParseUser对象的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!