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 Build a Weather App Working with JSON Setting CurrentWeather from JSON

Andrew Graves
.a{fill-rule:evenodd;}techdegree seal-36
Andrew Graves
iOS Development with Swift Techdegree Graduate 15,251 Points

Unreachable 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.setLocationLabel("Alcatraz Island, CA");

    return currentWeather;


1 Answer