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 (2015) Hooking Up the Model to the View Setting the Weather Icon

Noam Elbaz
Noam Elbaz
5,672 Points

One JSON typing mistake and the app fails

I built the weather app line by line... and the app would build and show me the UI but would not show any results. Turns out I mistyped one of the JSON values incorrectly "precipProbability" and that broke all the values.

Why does the whole app not function because of one mis-typed JSON value? I would think that the others should update and that one value would be broken.

1 Answer

Data is important. If we have a program that is responsible for launching a rocket and one of the values we expect to be present is not, yet the program overlooks this mistake and keeps processing we could be in for a major catastrophe. That's an extreme case, but it rings to the point that the data we work with in our applications must be accounted for and we have to be prepared for situations where certain values are not set or at all present. In your case, the fact that the key for the JSON changed was a show stopper and that is exactly how programs must function. You could write code to ensure the JSON contains the keys you expect and in a case where you got a malformed JSON you could then set default values.