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


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.