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 trialSandro Meschiari
18,418 Pointsvariable daily and hourly never use
guy i have a problem in my Stormy project, when i declare the JSONObject daily and JSONObject hourly android studio says that they are not in use, when i think it should automatically match them with the date taken from api.forecast. Can anybody help me?
2 Answers
Timothy Boland
18,237 PointsJSONArray data = forecast.getJSONArray("data");
should be:
JSONArray data = daily.getJSONArray("data");
JSONArray data = hourly.getJSONArray("data");
Sandro Meschiari
18,418 Pointsprivate Day[] getDailyForecast(String jsonData) throws JSONException { JSONObject forecast = new JSONObject(jsonData); String timezone = forecast.getString("timezone");
JSONObject daily = forecast.getJSONObject("daily");
JSONArray data = forecast.getJSONArray("data");
Day[] days = new Day[data.length()];
for (int i=0; i<data.length(); i++) {
JSONObject jsonDay = data.getJSONObject(i);
Day day = new Day();
day.setSummary(jsonDay.getString("summary"));
day.setTime(jsonDay.getLong("time"));
day.setIcon(jsonDay.getString("icon"));
day.setTemperatureMax(jsonDay.getDouble("temperatureMax"));
day.setTemperatureMin(jsonDay.getDouble("temperatureMin"));
day.setTimezone(timezone);
days[i] = day;
}
return days;
}
private Hour[] getHourlyForecast(String jsonData) throws JSONException {
JSONObject forecast = new JSONObject(jsonData);
String timezone = forecast.getString("timezone");
JSONObject hourly = forecast.getJSONObject("hourly");
JSONArray data = forecast.getJSONArray("data");
Hour[] hours = new Hour[data.length()];
for (int i=0; i<data.length(); i++ ) {
JSONObject jsonHour = data.getJSONObject(i);
Hour hour = new Hour();
hour.setSummary(jsonHour.getString("summary"));
hour.setIcon(jsonHour.getString("icon"));
hour.setTemperature(jsonHour.getDouble("temperature"));
hour.setTime(jsonHour.getLong("time"));
hour.setTimezone(timezone);
hours[i] = hour;
}
return hours;
}
I attached the code to it