有时ParseObject在响应中为空

时间:2015-11-23 08:28:46

标签: java android parse-platform nullpointerexception null

我有parseObject“Event”,链接到另一个parseObject“CustomUser”enter image description here

我发出此请求以通过EventObjectID

从Event获取自定义用户
eventID = "PRmB94GHrp";

ParseQuery<ParseObject> parseQuery = ParseQuery.getQuery("Event");
parseQuery.whereEqualTo("objectId", eventID);
parseQuery.include("author");
try {
    ParseObject eventParse = parseQuery.getFirst();
    eventParse.pin();
    eventParse.fetch();

    if (eventParse.getParseObject("author") != null) { //HERE IS SOMETIMES NULL
        customUserParseObject = eventParse.getParseObject("author"));
    }

在行 eventParse.getParseObject(“author”)!= null ,SOMETIMES为空

如何解决?

1 个答案:

答案 0 :(得分:0)

试试这个。

ParseQuery<ParseObject> query = ParseQuery.getQuery("Event");
query.include("author");
query.getInBackground("PRmB94GHrp", new GetCallback<ParseObject>() {
    public void done(ParseObject object, ParseException e) {
        if (e == null) {
            ParseObject authorObject = object.getParseObject("author"));
            //authorObject should contain the object
        }
    }
});