我在我的应用程序中使用此功能来制作排行榜。执行时,它永远不会到达for循环,我无法更新我的排行榜。是否有更好的实施方案?
public void updateLeaderboard(final Context context) {
Log.d("Leaderboard ", "Updating");
ParseQuery<ParseObject> query = ParseQuery.getQuery(KEY_USER_CLASS);
query.addDescendingOrder(KEY_LAST_LEVEL);
query.addAscendingOrder(KEY_CROSSED_AT);
query.whereNotEqualTo(KEY_ADMIN, true);
query.whereEqualTo(KEY_EMAIL_VERFIFIED, true);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> users, ParseException e) {
Log.d("Leaderboard ", "done() caled");
if (e == null) {
Log.d("Leaderboard ", "inside if");
for (int i = 0; i < users.size(); i++) {
ParseObject user = users.get(i);
Log.d("Leaderboard ",
"Updating user " + String.valueOf(i + 1));
user.put(KEY_RANK, i + 1);
user.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.d("Leader", "Saved");
} else {
Toast.makeText(context, e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
});
}
} else {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT)
.show();
}
}
});
Log.d("Leaderboard ", "Closing");
}
答案 0 :(得分:9)
最常见的原因是没有意识到“用户”,“角色”和“安装”类是特殊的,它们的实际名称是“_User”,“_ Role”和“_Installation”,尽管对用户进行查询class推荐的方法是:
ParseQuery<ParseUser> query = ParseUser.getQuery();