Search code examples
androiditerationparse-serveryelp

Why does iterating through a for loop with a findInbackGround() fail?


So I have decided to play with the yelp API as a challenge for myself... Clearly I bit more than I can chew... What I am trying to do is iterate through a YelpAPI Response and check if it exists in a column, however it checks only the last value in the Response and it doesn't even match that... Is there an alternative? I think the issue is limited to the fact that it works on a new thread,overwriting the old one each time through the iteration... There might be a completely different way of approaching this.. Below is the code

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());
}

Solution

  • I found a rather unrelated solution, the problem was that reading items from the parsequery meant that every item in that class had to be set to public read/write, which wasn't set before.