我正在尝试查询Parse数据库并得到错误:无法解析符号'FindCallBack'。 我尝试过使用'query.find',但我被告知'findInBackground'更有效。 主要目标是查询信息并迭代列表以供将来使用。 查询本身在我使用'query.find'时有效,但迭代失败,就像我正在尝试访问无效字段一样。
'FindCallBack'版本
import com.parse.Parse;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.SaveCallback;
import com.parse.ParseException;
import com.parse.FindCallback;
import java.util.Calendar;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.List;
public class ListNodeActivity extends AppCompatActivity
{
private Task t = new Task();
private Spinner spin;
private Spinner empolyeeSpinner;
private int task_id=1;
private String time_Date_str = null;
private Locations returned_selc_loc;
private EditText loc;
private ParseObject parse_task=null;
private DBManager dbm;
private static final int ACTIVITY_SELECT_LOCATION = 0;
private ParseObject team_members = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_node);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//check is username & password exist
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("OTSUser");
query.whereContains("TeamName", Globals.team_name);
query.whereEqualTo("IsManager",0);
query.findInBackground(new FindCallBack<ParseObject>() {
public void done(List<ParseObject> usrs;ParseException e) {
if (e == null) {
for (int i = 0; i < usrs.size(); i++) {
Log.w("debug", usrs.get(i).getString("Userame"));
}
} else {//handle the error
}
}
});
}
}
'query.find'版本
//check is username & password exist
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("OTSUser");
query.whereContains("TeamName", Globals.team_name);
query.whereEqualTo("IsManager",0);
List<ParseObject> usrs=null;
try {
usrs = query.find();
Log.w("debug","size of usrs "+usrs.size());
for (int i = 0; i < usrs.size(); i++)
{
// empolyeeSpinnerAdapter.add(usrs.get(i).getString("Userame"));
Log.w("debug",usrs.get(i).getString("Userame"));
}
} catch (ParseException e) {}
答案 0 :(得分:1)
你有两个拼写错误导致此失败。首先,类名为FindCallback
,小写为“b”。
你也在使用';'而不是','来分隔done(...)
方法中的参数。将方法更改为以下内容,您应该在路上。
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> usrs, ParseException e) {
if (e == null) {
for (int i = 0; i < usrs.size(); i++) {
Log.w("debug", usrs.get(i).getString("Userame"));
}
} else {//handle the error
}
}
});