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 trialManas Vijaywargiya
12,598 Pointsdata is not displayed. @benjakuben
After making the whole weather data app, the app in not able to retrieve data from the site - dark sky API
2 Answers
Ben Jakuben
Treehouse TeacherI'll walk you through my troubleshooting steps, but take a minute and see if you can trace it yourself by looking at the error message from logcat, because it'll help you solve these kinds of issues when they inevitably pop up in the future. This is a common error, unfortunately! :)
(By the way, I removed your API code from the paste above.)
I plugged your code into my app and found the following error in logcat:
02-13 15:54:54.127 6177-6723/teamtreehouse.com.stormy E/MainActivity: Exception caught :
org.json.JSONException: No value for precipProbablity
at org.json.JSONObject.get(JSONObject.java:389)
at org.json.JSONObject.getDouble(JSONObject.java:444)
at teamtreehouse.com.stormy.ui.MainActivity$override.getCurrentDetails(MainActivity.java:163)
at teamtreehouse.com.stormy.ui.MainActivity$override.static$access$500(MainActivity.java:31)
at teamtreehouse.com.stormy.ui.MainActivity$override.access$dispatch(MainActivity.java)
at teamtreehouse.com.stormy.ui.MainActivity.access$500(MainActivity.java:0)
at teamtreehouse.com.stormy.ui.MainActivity$2.onResponse(MainActivity.java:107)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:135)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
If you click on the link in logcat to the error in MainActivity.java (line 163 in my code), it takes you to this line of code:
currentWeather.setPrecipChance(currently.getDouble("precipProbablity"));
I manually confirmed that the JSON was coming back as expected from the Dark Sky service, but I didn't really have to.
Knowing that precipProbability
was in the JSON data as expected, I looked more closely at this line of code. I found an easy-to-miss typo in the key you're passing in to the getDouble()
method: you're missing a lowercase "i" in "Probability".
Manas Vijaywargiya
12,598 PointsThanks ben.....
Manas Vijaywargiya
12,598 PointsManas Vijaywargiya
12,598 PointsMainActivity.java:- Ben Jakuben