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 trialjen0vah
2,636 PointsSetting the temp to Celsius instead of Fahrenheit
since I'm living outside the US the Fahrenheit unit is something I'm not familiar with. so I checked the forecast API and they already have the option through changing the API link https://developer.forecast.io/docs/v2 => units=[si]
so I tried changing the forecast link in my MainActivity class like this:
String settings = "units=[si]";
String apiKey = "27974c4bc33201748eaf542a6769c3b7";
String forecastUrl = "https://api.forecast.io/forecast/" + apiKey +
"/" + latitude + "," + longitude + "," + settings ;
`
but that doesnt seem to work that well since I'm getting a FATAL Exception like that
10-19 13:17:40.437 25848-25873/onemanarmystudios.stormy E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher 10-19 13:17:40.437 25848-25873/onemanarmystudios.stormy E/AndroidRuntime: Process: onemanarmystudios.stormy, PID: 25848 10-19 13:17:40.437 25848-25873/onemanarmystudios.stormy E/AndroidRuntime: java.lang.IllegalStateException: not valid as a java.net.URI: https://api.forecast.io/forecast/27974c4bc33201748eaf542a6769c3b7/50.73,7.1,units=[si]
Was I thinking too naive there? and how to fix it?
4 Answers
Jeremiah Montano
7,221 PointsI was able to pull it up in forecast.io using the following link:
https://api.forecast.io/forecast/(apiKey)/37.8267,-122.423?units=si
at the end of your lat/longitude, include ?units=si. Pulled it up for me.
Hope this helps!
Jacob Bergdahl
29,119 PointsI used the same solution as Jeremiah when I made the app, and it worked perfectly! Note that you can also change the language by adding the "lang" (language) keyword, like so: ?units=si&lang=en
jen0vah
2,636 Pointsthanks :)! the forcast link seems to work now at least it doesnt throw an exception anymore but somewhere theres suddenly still another problem.. When I start the app in the emulator and its updating its weather data theres always the error message popping up which you create some lessons earlier. When I hit the "update data" button its popping up again without updating the data or showing it at all ...
//Edit: In the end one space character ruined my whole app and since it wasn't showing as an Error in the code it was not easy to spot the problem. All done now and it works. Thanks guys!
Mala Johri
Courses Plus Student 881 Pointsworked for me as well. \/