java - 查询 ParseObject

标签 java android parse-platform

我正在尝试使用 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/

相关文章:

Java JUnit Eclipse 错误 : Type mismatch cannot convert from void to double

java - 确定 LayoutManager 预布局中出现的 View

Android AsyncTask 访问 Activity Context 的更好方式

java - Android后台服务定时器无法正常工作

android - 如何在Android中初始化parse.com代码

java - 将带有空格分隔符的字符串转换为数组。并像字符串一样输出这个数组

java - 从列中获取数据,然后选择数据所属的整行

java - 错误 1064 : SQL syntax error

javascript - 关于解析的待办事项列表教程不允许我查看该应用程序

ios - 无法从 AppDelegate 中实例化 rootViewController