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!
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

yotam laor
1,319 Pointsbuilding a weather app course
Hi,
I am following the 'Build a weather app' course and find some difficulties with the JSON files.
When running this code the icon resource acquired is a null value.
private CurrentWeather getCurrentDetails(String jsonData) throws JSONException {
JSONObject forecast = new JSONObject(jsonData);
String timeZone =forecast.getString("timezone");
Log.i(TAG,"From JSON: " + timeZone);
JSONObject currently = forecast.getJSONObject("currently");
CurrentWeather currentWeather = new CurrentWeather();
currentWeather.setHumidity(currently.getDouble("humidity"));
currentWeather.setTime(currently.getLong("time"));
currentWeather.setIcon(currently.getString("icon"));
currentWeather.setPrecipitation(currently.getDouble("precipProbability"));
currentWeather.setSummary(currently.getString("summary"));
currentWeather.setTemperature(currently.getDouble("temperature"));
//currentWeather.setTtimeZone(currently.getString(timeZone));
currentWeather.setTtimeZone(timeZone);
Log.d(TAG, currentWeather.getFormattedTime());
return new CurrentWeather();
}
Does anyone know how to solve it and get a true value from the JSON file? Thanks
1 Answer

Ryan Chatterton
5,914 Pointscan you post the json?
currently:
{
"time":1454814475,
"summary":"Partly Cloudy",
"icon":"partly-cloudy-night",
"nearestStormDistance":6,
"nearestStormBearing":122,
"precipIntensity":0,
"precipProbability":0,
"temperature":57.53,
"apparentTemperature":57.53,
"dewPoint":46.79,
"humidity":0.67,
"windSpeed":2.19,
"windBearing":318,
"visibility":8.34,
"cloudCover":0.43,
"pressure":1026.74,
"ozone":295.73
}
this is how I did it.
private Current getCurrentDetails(String jsonData) throws JSONException {
JSONObject forecast = new JSONObject(jsonData);
String timezone = forecast.getString("timezone");
JSONObject currently = forecast.getJSONObject("currently");
Current current = new Current();
current.setHumidity(currently.getDouble("humidity"));
current.setTime(currently.getLong("time"));
current.setIcon(currently.getString("icon"));
current.setPrecipChance(currently.getDouble("precipProbability"));
current.setSummary(currently.getString("summary"));
current.setTempature(currently.getDouble("temperature"));
current.setTimeZone(timezone);
Log.d(TAG, current.getFormattedTime());
Log.i(TAG, "From JSON: " + timezone);
return current;
}