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.


Muhammad Sodikin
Muhammad Sodikin
2,815 Points

Help, error on "org.json.JSONException: No value for Time"

I'm working on Building Weather App, and at stage Cleaning Up the Date and Time,

at CurrentWeather.java has

public String getFormattedTime() { SimpleDateFormat formatter = new SimpleDateFormat("h:mm a"); formatter.setTimeZone(TimeZone.getTimeZone(getTimeZone())); Date dateTime = new Date(getTime() * 1000); String timeString = formatter.format(dateTime);

    return timeString;


and MainActivity.java has:

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();

    Log.d(TAG, currentWeather.getFormattedTime());

    return currentWeather;


can't find the time value.

2 Answers


You're currently trying to get the time via currentWeather.setTime(currently.getLong("Time")); with the key Time. However, the key is "time".

Muhammad Sodikin
Muhammad Sodikin
2,815 Points

Thanks James Simshaw. Oh man, that really bad only upper case can give wrong result. Heheh. I get it right on the Log cat now. :D

You're welcome. Case sensitivity causes all kinds of "fun" bugs to troubleshoot. Good luck with Android development.

Muhammad Sodikin
Muhammad Sodikin
2,815 Points

Oh yeah. Let's me buy you a drink, maybe. How do you doing on track now? Working on something new now aye?

I'm finished with what's currently available on the track and am working on a custom image cropping tool for one of my larger projects.

Muhammad Sodikin
Muhammad Sodikin
2,815 Points

projects...that sound lot of of them...haha, I will help u if I'm experts after this. Bye James.