从ParseQuery中访问变量[JAVA]

时间:2015-08-25 14:14:21

标签: java android parse-platform

我无法访问从实际解析查询之外的解析中检索到的变量。它告诉我它不能为最终变量赋值。

    final String startTime;
    ParseQuery<ParseObject> startQuery = ParseQuery.getQuery("clockIn");
    startQuery.getInBackground(clockInId, new GetCallback<ParseObject>() {
        public void done(ParseObject clockIn, ParseException e) {
            if (e == null) {
                startTime = clockIn.getString("Time");
            } else {
                // something went wrong
            }
        }
    });

    //Retrieve clockOutId (ObjectID for clockOutTime)
    final String endTime;
    ParseQuery<ParseObject> endQuery = ParseQuery.getQuery("clockOut");
    endQuery.getInBackground(clockOutId, new GetCallback<ParseObject>() {
        public void done(ParseObject clockOut, ParseException e) {
            if (e == null) {
                endTime = clockOut.getString("Time");
            } else {
                // something went wrong
            }
        }
    });

我需要访问endTime和startTime然后采取差异,但它告诉我由于最终问题而没有初始化变量

1 个答案:

答案 0 :(得分:0)

&#34;最终&#34;变量无法修改,您可以在类的开头声明这些变量,然后赋值。

试试这个......

public class YourActivityOrWhatYouNeed{
    String startTime="";
    String endTime="";
    ...
    ...
    ...


ParseQuery<ParseObject> startQuery = ParseQuery.getQuery("clockIn");
startQuery.getInBackground(clockInId, new GetCallback<ParseObject>() {
    public void done(ParseObject clockIn, ParseException e) {
        if (e == null) {
            startTime = clockIn.getString("Time");
        } else {
            // something went wrong
        }
    }
});

//Retrieve clockOutId (ObjectID for clockOutTime)
ParseQuery<ParseObject> endQuery = ParseQuery.getQuery("clockOut");
endQuery.getInBackground(clockOutId, new GetCallback<ParseObject>() {
    public void done(ParseObject clockOut, ParseException e) {
        if (e == null) {
            endTime = clockOut.getString("Time");
        } else {
            // something went wrong
        }
    }
});

希望它可以帮到你