我正在尝试使用 Parse 查询获取对象。
这是我的代码:
ParseQuery<ParseObject> query = ParseQuery.getQuery("Conference");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> results, ParseException e) {
if (e == null) {
// Results were successfully found from the local datastore.
} else {
showLog(e.toString());
}
}
});
我收到这个错误:
com.parse.ParseException: java.lang.IllegalStateException: ParseObject has no data for 'objectId'. Call fetchIfNeeded() to get the data.
顺便说一句,我的 Conference
类包含指针。
最佳答案
如果您直接从 Parse 查询,您可以:
ParseQuery<ParseObject> query = ParseQuery.getQuery("Conference");
...
query.include("name_of_the_column_containing_a_pointer");
query.include("another_pointer_column");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> results, ParseException e) {
if (e == null) {
// You can now access the pointers specified in the include
} else {
showLog(e.toString());
}
}
});
否则,如果您正在查询本地数据存储:
ParseQuery<ParseObject> query = ParseQuery.getQuery("Conference");
...
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> results, ParseException e) {
if (e == null) {
ParseObject parseObject = results.get(0); // Get the object
parseObject.fetchIfNeededInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject result, ParseException e) {
if (e == null)
// Do something with result
}
}
} else {
showLog(e.toString());
}
}
});
关于java - 查询 ParseObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33802581/