我正在尝试编写一个方法来计算数据库中用户条目的数量。我知道,如果在一个巨大的数据库上运行,这将是低效的,因此将其限制为仅过去24小时内的数据。当我尝试运行它时,会出现错误突出显示网络连接中存在错误。我想要做的是遍历所有用户名并计算他们提交到数据库的次数。刚刚列出数据。任何帮助将不胜感激。
public void display3km(ParseGeoPoint userLocation) {
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
listCombosNearBy.setAdapter(arrayAdapter);
final Date yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
final ParseQuery<ParseObject> query3 = ParseQuery.getQuery("FavFlavours");
query3.whereGreaterThanOrEqualTo("createdAt", yesterday);
query3.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(final List<ParseObject> parseQuery, ParseException e) {
final ParseUser[] allCombosArray = new ParseUser[parseQuery.size()];
System.out.println(allCombosArray);
for (ParseObject object : parseQuery) {
for (int i = 0; i < allCombosArray.length; i++) {
object.getParseUser("createdBy").fetchIfNeeded().getString("username");
allCombosArray[i] = object.getParseUser("createdBy");
query3.whereEqualTo("createdBy", allCombosArray[i]);
query3.countInBackground(new CountCallback() {
@Override
public void done(int count, ParseException e) {
final Set<String> results = new HashSet<String>();
if (e == null) {
results.add(allCombosArray + " " + count);
System.out.println(results);
}
arrayAdapter.addAll(results);
}
});
}
}
}
});
}
}
这是发给我的日志猫代码。
02-25 22:36:26.777: E/AndroidRuntime(9312): FATAL EXCEPTION: main
02-25 22:36:26.777: E/AndroidRuntime(9312): Process: com.lfg.fyp.taste_a_saurus, PID: 9312
02-25 22:36:26.777: E/AndroidRuntime(9312): java.lang.RuntimeException: This query has an outstanding network connection. You have to wait until it's done.
02-25 22:36:26.777: E/AndroidRuntime(9312): at com.parse.ParseQuery.checkIfRunning(ParseQuery.java:965)
02-25 22:36:26.777: E/AndroidRuntime(9312): at com.parse.ParseQuery.checkIfRunning(ParseQuery.java:959)
02-25 22:36:26.777: E/AndroidRuntime(9312): at com.parse.ParseQuery.whereEqualTo(ParseQuery.java:1571)
02-25 22:36:26.777: E/AndroidRuntime(9312): at com.lfg.fyp.taste_a_saurus.StatsUsers$1.done(StatsUsers.java:111)
02-25 22:36:26.777: E/AndroidRuntime(9312): at com.lfg.fyp.taste_a_saurus.StatsUsers$1.done(StatsUsers.java:1)
02-25 22:36:26.777: E/AndroidRuntime(9312): at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:115)
02-25 22:36:26.777: E/AndroidRuntime(9312): at android.os.Handler.handleCallback(Handler.java:739)
02-25 22:36:26.777: E/AndroidRuntime(9312): at android.os.Handler.dispatchMessage(Handler.java:95)
02-25 22:36:26.777: E/AndroidRuntime(9312): at android.os.Looper.loop(Looper.java:148)
02-25 22:36:26.777: E/AndroidRuntime(9312): at android.app.ActivityThread.main(ActivityThread.java:5417)
02-25 22:36:26.777: E/AndroidRuntime(9312): at java.lang.reflect.Method.invoke(Native Method)
02-25 22:36:26.777: E/AndroidRuntime(9312): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
02-25 22:36:26.777: E/AndroidRuntime(9312): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
我正在用Java编写一个Android应用程序。我正在使用eclipse与android jar导入。