使用以下查询,我想获得一个ParseUsers列表,该列表仅包含在queryColumns列表中定义的列的子集。我成功收到了结果,但是当我尝试将它们固定到本地数据存储区时,我收到了异常:
com.parse.ParseException: java.lang.IllegalStateException: ParseObject has no data for this key. Call fetchIfNeeded() to get the data.
我无法理解为什么......如果"复杂"像ParseObjects这样的列是什么?我查询的数据只是由字符串和布尔值组成。
final List<String> queryColumns = Arrays.asList(
"username", // String
"email", // String
"avatarCountry", // String
"avatarId", // String
"showCountry" // Boolean
"facebookId" // String
);
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.selectKeys(queryColumns);
query.whereContainedIn("facebookId", fids);
query.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> result, ParseException ex) {
if (ex == null) {
// do stuff... then pin the results
ParseUser.pinAllInBackground(CACHED_PLAYERS_LABEL, result, new SaveCallback() {
@Override
public void done(ParseException pinEx) {
// EXCEPTION HERE: java.lang.IllegalStateException: ParseObject has no data for this key. Call fetchIfNeeded() to get the data.
}
});
}
}
});
答案 0 :(得分:1)
您的例外情况已包含答案:Call fetchIfNeeded() to get the data.
因此,请按以下方式更改您的代码:
query.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> result, ParseException e) {
ParseObject.fetchAllIfNeededInBackground(result, new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> list, ParseException ex) {
if (ex == null) {
ParseObject.pinAllInBackground(CACHED_PLAYERS_LABEL, result, new SaveCallback() {
@Override
public void done(ParseException e) {
}
});
}
}
});
}
});