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 trialAndrew Graves
iOS Development with Swift Techdegree Graduate 15,251 PointsUnreachable JSON object
When creating a JSONObject as so
JSONObject currently = forecast.getJSONObject("currently");
Android Studio flags it as an unreachable statement. The entire class is below for some more context. The String "timezone" is reachable by the way.
private CurrentWeather getCurrentDetails(String jsonData) throws JSONException{ JSONObject forecast = new JSONObject(jsonData);
String timezone = forecast.getString("timezone");
Log.i(TAG, "From JSON " + timezone);
return null;
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.setLocationLabel("Alcatraz Island, CA");
currentWeather.setPrecipChance(currently.getDouble("precipProbability"));
currentWeather.setSummary(currently.getString("summary"));
currentWeather.setTemperature(currently.getDouble("temperature"));
return currentWeather;
}
1 Answer
Andrew Graves
iOS Development with Swift Techdegree Graduate 15,251 PointsNever mind, I figured out it was a simple mistake. By returning null early on, I was ending the function before It was supposed to end.