Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts

Tuesday, 2 January 2018

MeteoLecce (9): new design!

I want to update the development of my app MeteoLecce. I'll start we the two following pictures:

The main activity of MeteoLecce
Do you see some changes?
I reduced the information on the first activity and I compacted them; in this way we have a much simpler reading of them (I also introduced the colors).

The activity related to the next 3 days weather forecast

Relating to second activity's infos I added 4 icons for each day (at the times: 0 - 6 - 12 and 6 P.M.). Tempeatures are two: high/low.

I hope to share my app on Google Play soon.

Friday, 15 September 2017

Working on Json datas: if a key is missing

One of the things I have lernt today it was the possibility to know if an element on an Json array exists. The necessity of this is information is strong to prevent a NullPointException.

For exemple (on an Openweathermap string) we have this information in Json format:

{"coord":{"lon":18.17,"lat":40.36},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"base":"stations","main":{"temp":296.18,"pressure":1013,"humidity":100,"temp_min":295.15,"temp_max":297.15},"visibility":10000,"wind":{"speed":1.5},"clouds":{"all":0},"dt":1505505300,"sys":{"type":1,"id":5746,"message":0.0031,"country":"IT","sunrise":1505449736,"sunset":1505494485},"id":6542124,"name":"Lecce","cod":200}

As you can see there at least one difference (I marked in red):
{"coord":{"lon":18.17,"lat":40.36},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"base":"stations","main":{"temp":296.14,"pressure":1013,"humidity":83,"temp_min":295.15,"temp_max":297.15},"visibility":10000,"wind":{"speed":5.1,"deg":190},"clouds":{"all":0},"dt":1505506500,"sys":{"type":1,"id":5749,"message":0.0022,"country":"IT","sunrise":1505449738,"sunset":1505494482},"id":6542124,"name":"Lecce","cod":200} 
Yes, in these second infos the data value for "deg" is missing.


How we can resolve it?

Well, we can use the has method, so we can write something like this:

if (json.getJSONObject("wind").has("deg"))

Well done...