Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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