为什么使用 findInbackGround() 遍历 for 循环会失败?
Why does iterating through a for loop with a findInbackGround() fail?
所以我决定玩 yelp API 作为对自己的挑战...很明显我有点吃不消...我想做的是迭代通过 YelpAPI 响应并检查它是否存在于列中,但是它仅检查响应中的最后一个值并且它甚至不匹配......是否有替代方案?我认为这个问题仅限于它在一个新线程上工作,每次迭代都会覆盖旧线程这一事实......可能有一种完全不同的方法来解决这个问题......下面是代码
localityVenueLocations = new String[2 * response.body().businesses().size()][4];
ParseGeoPoint venuePoint;
String venueName;
for (int i = 0; i < response.body().businesses().size(); i++) {
venuePoint = new ParseGeoPoint(response.body().businesses().get(i).location().coordinate().latitude(), response.body().businesses().get(i).location().coordinate().longitude());
venueName = response.body().businesses().get(i).name();
venue = new ParseObject("HotSpots");
//Log.i("AppInfo", venueName);
ParseQuery < ParseObject > qVenues = ParseQuery.getQuery("HotSpots");
//int size = qVenues.whereEqualTo("venue", venueName).find().size();
//Log.i("AppInfo", String.valueOf(size));
qVenues.whereEqualTo("venue", venueName).findInBackground(new FindCallback < ParseObject > () {@
Override
public void done(List < ParseObject > objects, ParseException e) {
if (e == null) {
if (objects.size() > 0) {
Log.i("AppInfo", "Match for " + venueName);
Log.i("AppInfo", "Success checking data");
Log.i("AppInfo", String.valueOf(objects.size()));
} else {
Log.i("AppInfo", "No match for " + venueName);
Log.i("AppInfo", "Failed at query");
Log.i("AppInfo", String.valueOf(objects.size()));
}
} else {
Log.i("AppInfo", "Failed at error");
e.getCode();
}
}
});
Log.i("App Info, Business", venueName.toString());
Log.i("App Info, Lat", venuePoint.toString());
}
我找到了一个相当不相关的解决方案,问题是从解析查询中读取项目意味着 class 中的每个项目都必须设置为 public read/write,这是之前设置过。
所以我决定玩 yelp API 作为对自己的挑战...很明显我有点吃不消...我想做的是迭代通过 YelpAPI 响应并检查它是否存在于列中,但是它仅检查响应中的最后一个值并且它甚至不匹配......是否有替代方案?我认为这个问题仅限于它在一个新线程上工作,每次迭代都会覆盖旧线程这一事实......可能有一种完全不同的方法来解决这个问题......下面是代码
localityVenueLocations = new String[2 * response.body().businesses().size()][4];
ParseGeoPoint venuePoint;
String venueName;
for (int i = 0; i < response.body().businesses().size(); i++) {
venuePoint = new ParseGeoPoint(response.body().businesses().get(i).location().coordinate().latitude(), response.body().businesses().get(i).location().coordinate().longitude());
venueName = response.body().businesses().get(i).name();
venue = new ParseObject("HotSpots");
//Log.i("AppInfo", venueName);
ParseQuery < ParseObject > qVenues = ParseQuery.getQuery("HotSpots");
//int size = qVenues.whereEqualTo("venue", venueName).find().size();
//Log.i("AppInfo", String.valueOf(size));
qVenues.whereEqualTo("venue", venueName).findInBackground(new FindCallback < ParseObject > () {@
Override
public void done(List < ParseObject > objects, ParseException e) {
if (e == null) {
if (objects.size() > 0) {
Log.i("AppInfo", "Match for " + venueName);
Log.i("AppInfo", "Success checking data");
Log.i("AppInfo", String.valueOf(objects.size()));
} else {
Log.i("AppInfo", "No match for " + venueName);
Log.i("AppInfo", "Failed at query");
Log.i("AppInfo", String.valueOf(objects.size()));
}
} else {
Log.i("AppInfo", "Failed at error");
e.getCode();
}
}
});
Log.i("App Info, Business", venueName.toString());
Log.i("App Info, Lat", venuePoint.toString());
}
我找到了一个相当不相关的解决方案,问题是从解析查询中读取项目意味着 class 中的每个项目都必须设置为 public read/write,这是之前设置过。