-1

I need to know how to halt code execution until my mobile service query finishes. I am getting a null pointer exception because the code is attempting to access the query data before the query finishes.

---Code---
mEmployeeTable.execute(new TableQueryCallback<Employee>() {
 //get employees
 ...
});

//In this activity i attempt to use the info loaded from the query above
//however since the query has not completed i get null pointer exception
startActivity(intent);
4

1 回答 1

1

只有在收到回调时才需要启动活动,类似于下面的代码:

mEmployeeTable.execute(new TableQueryCallback<Employee>() {
  @Override
  public void onCompleted(List<Employee> employees, int count, Exception exception, ServiceFilterResponse response) {
    if (exception != null) {
      // error happened during query, deal with it appropriately
    } else {
      // store the loaded employees somewhere
      startActivity(intent);
    }
  }
});
于 2013-10-02T16:10:52.570 回答