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

taubin
taubin
8,705 Points

Cannot resolve symbol data when creating the Hour array

When adding the array for Hour, data.length gives an error stating it cannot resolve the symbol

I'm not sure what I've missed here.

private Hour[] getHourlyForecast(String jsonData) throws JSONException{
    JSONObject forecast = new JSONObject(jsonData);
    String timezone = forecast.getString("timezone");
    JSONObject hourly = forecast.getJSONObject("hourly");
    JSONArray date = hourly.getJSONArray("data");

    Hour[] hours = new Hour[data.length()];

    for (int i = 0; i < data.length(); i++){
        JSONObject jsonHour = data.getJSONObject(i);
    }
}

The full source is on bitbucket here https://bitbucket.org/dustin_p/stormy/src/b6054c3f5fa664cb15570d074375063cd1904135/app/src/main/java/taubin/us/stormy/ui/MainActivity.java?at=master I'm sure I've just missed something, but I'm not seeing it. Any help would be greatly appreciated.

1 Answer

taubin
taubin
8,705 Points

I believe I found the issue after looking at the example provided at the beginning of the lesson. I had JSONArray date = hourly.getJSONArray("data"); instead of JSONArray data = hourly.getJSONArray("data"); on line 188

That seems to be the only change between the files that I can see and changing it seems to have corrected the issue.