Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Lists and Adapters (2015) Updating the Data Model From JSONArray to a Java Array

Will Macleod
PLUS
Will Macleod
Courses Plus Student 18,780 Points

Cannot resolve symbol 'i' in Day array

I've followed exactly what Ben has typed out but my code cant resolve symbol 'i'

 private Day[] getDailyForecast(String jsonData) throws JSONException {
        JSONObject forecast = new JSONObject(jsonData);
        String timezone = forecast.getString("timezone");
        JSONObject daily = forecast.getJSONObject("daily");
        JSONArray data = daily.getJSONArray("data");

        Day[] days = new Day[data.length()];

        for (int i = 0; i < data.length(); i++); {
            JSONObject jsonDay = data.getJSONObject(i); //<--- this is where I get the error 'Cannot resolve symbol'
            Day day = new Day();

            day.setSummary(jsonDay.getString("summary"));
            day.setIcon(jsonDay.getString("summary"));
            day.setTemperatureMax(jsonDay.getDouble("temperatureMax"));
            day.setTime(jsonDay.getLong("time"));
            day.setTimezone(timezone);

            days[i] = day;
        }

        return days;
    }

Thank you very much.

1 Answer

You have a semicolon after the closing paren of the for loop. This ends the for statement and makes the declared i variable no longer valid.

 for (int i = 0; i < data.length(); i++);  // <-- Remove that semicolon