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

General Discussion

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Forum Contest: Build an Android Weather App

EDIT: This contest has ended. Congratulations, Ratik Sharma, on your winning entry! The next contest is up: Create a WebGL Scene

Happy June, Android developers!

This week's Forum Contest is for Android development. We are going to use a free API from forecast.io to build a simple weather app!

After you've watched the video, please read the details below carefully. We're looking forward to your entries!

Contests Rules:
This contest is pretty open ended. The main objective is to get data from the forecast.io API and display it in a meaningful way. It's up to you if you want to concentrate on some key data or try to use as much as possible. The goal is to present whatever information you choose in a clear and appealing way. Create your app as a native app; i.e. the app must be installable on Android devices (web apps are not permitted).

Help:
To hardcode a location, you can use this example for Orlando, FL. Lat: 28.4158, Long: -81.2989. To get coordinates for a different location, you can use Google Maps. Simply locate the place you want to get data for, right-click on the map and select "What's Here?" A popup will show with the latitude and longitude of that location.

If you'd like a decent tutorial on how to get your current location using the Android APIs, check out this tutorial by Lars Vogella.

How to Enter:
Post a link as an answer to this post. It can be a link to downloadable project files or a GitHub repo. If you want to submit a link to an app on Google Play (you're encouraged to publish your entries!), then also provide a link to the source code. Source code is required for this contest.

Due Date:
All entries must be submitted by June 8th at 11:59pm ET. Here's a timezone chart so you can see what time that is for your locale.

Prize:
The entries will be judged by Treehouse teachers based on both design and code. One winner will receive a free month of Treehouse Pro (formerly called "Gold") on us! We'll announce the winner on June 9th and reveal the next contest.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

On second thought, maybe this should be a Swift-based contest...

Awesome contest, but I have a doubt: is it really the due date just 2 days from now?

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Sorry! That was a typo. It's due the 8th. I've corrected the original post.

Devon Boyer
Devon Boyer
4,020 Points

Bring on the iOS contests! Do you guys have any planned in the future?

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Devon Boyer, indeed we do! We don't have a hard schedule for these, so keep an eye on the announcements each Monday morning. :)

15 Answers

John Coffin
John Coffin
10,359 Points

Challenge accepted. The game is afoot, Jakuben.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Upvote! Looking forward to your submission. :)

Andrew Pritykin
Andrew Pritykin
6,574 Points

Interesting. Happy to see that we are getting more love for Android. May take a crack at it

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Me too! I'm back on Android full time, so I plan on refreshing and releasing a lot this year and beyond. :)

Ratik Sharma
Ratik Sharma
32,885 Points

Hello, good people of the forum! I have been working on the application lately and am faced with a funny little error. On calling connection.getContentLength() (connection is an HTTPURLConnection object), forecast.io is returning -1. Has anybody stumbled upon such an issue? If so, what did you do?

Code Snippet:

if (responseCode == HttpURLConnection.HTTP_OK) {
    InputStream inputStream = connection.getInputStream();
    Reader reader = new InputStreamReader(inputStream);
    int contentLength = connection.getContentLength(); // returns -1 

    ...
}
Ben Jakuben
Ben Jakuben
Treehouse Teacher

Hey Ratik!

You're running into a bug with the code we use in the Blog Reader project based on how some servers handle the content length property. For alternate code to use, try this code from another Forum Post:

if (responseCode == HttpURLConnection.HTTP_OK) {
    HttpEntity entity = response.getEntity();
    InputStream content = entity.getContent();
    BufferedReader reader = new BufferedReader(new InputStreamReader(content));
    String line;
    while((line = reader.readLine()) != null){
        builder.append(line);
    }

    jsonResponse = new JSONObject(builder.toString());
}
else {
    Log.i(TAG, String.format("Unsuccessful HTTP response code: %d", responseCode));
}
Ratik Sharma
Ratik Sharma
32,885 Points

Thanks, Ben Jakuben! Although, does this imply that getting JSON from different sites requires different code? If so, how does one know exactly what code to use when dealing with such a situation? This question is just for further knowledge!

Ben Jakuben
Ben Jakuben
Treehouse Teacher

No, this is better code to use. The implementation in Blog Reader uses the incorrect assumption that content length will always be valid. My mistake for not testing this code on other sources. I had originally intended on following up on this project with another stage or mini project about replacing this code with a 3rd party library, but never got around to it. I will be refreshing it soon, though, and I'll talk about something like OkHttp then.

Heads up! I don't believe there is a notification out for this contest? I'm guessing many people rely mainly on their notification bell for Forum Contest announcements. I would hate for interested people to miss out on this one because they didn't know about it! :(

Just sayin'.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Thanks, Hans! Just sent it out. I missed that on Monday!

Yeah actually I just found out about this a hour ago looks like I have time to make up now

So I have a question to fellow dev's is anyone including in their scope the full forecast query scope range available by the Forecast API of 60 years in the past to 10 years in the future?

Hello, First of all i want to thank you and all treehouse team for your effort to provide us with this great courses. So here is my contest entry:

Google Play

GitHub

Good luck to everyone taking part in this contest!

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Looks great!! Can't wait to check it out. I'll look at all entries and code on Monday morning after the deadline.

Ratik Sharma
Ratik Sharma
32,885 Points

Hello all! Here is my submission for the contest: Nuvole

Note: The app has a dependency on an open source GitHub project which I've included in the files. Eclipse uses (I use Eclipse) can add it as a library to the app while viewing the code.

Learned loads of stuff while making this and am pretty proud of the end result. What else can one ask for? All the best, fellow developers!

Hello,

Well, here is my basic but working app. Thanks Treehouse, I feel a lot more comfortable working with JSON data.

Google Play: https://play.google.com/store/apps/details?id=com.spacecasestudios.fourcast GitHub: https://github.com/ryanloerzel/FourCastWeatherApp

Hey! Didn't get as much done as I would have liked, but a pretty good start. I'll definitely keep working on it.

GitHub: https://github.com/nmillward/WeatherApp

Thanks for the contest! These are a lot of fun!

-Nick

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Hey everyone! Thanks so much for submitting this week! Once again, you are all an inspiration. I loved what you all have created. After a bit of debate, I've selected Ratik Sharma as the winner. Congratulations, Ratik! :smile::clap::sunny::cloud::umbrella:

Ratik's Nuvole app has a really elegant and simple design with graceful animations. He implemented a fun "swipe to share" gesture and included a cool 3rd party library called ShowcaseView to show it when the app first runs. He added a really fun refresh animation and sound and uses geolocation to get the user's current location. Ratik, the only thing missing is having it up on Google Play!

There is a bug with the degree symbol you are using in the string. On a Mac, it gets converted to an infinity symbol. You can get around this by using the unicode value instead:

mTemperatureTextView.setText(WeatherDataHelper.temperature + "\u00B0");

The other thing I would recommend would be to get the user's current location from your LocationListener, not the time zone in the Forecast payload. That will give you the accurate city name, whereas the name in the API is very generic.

Again, fantastic work by all of you, and thanks for participating! Look for more Android Forum contests down the road, and keep your eyes on the Forum this morning for the next contest announcement. :)

Ratik Sharma
Ratik Sharma
32,885 Points

Woohoo! And yes, I'll get cracking on those fixes real soon and then push the app out to the PlayStore. Cheers, everyone!

Akshay Shivpuri
Akshay Shivpuri
2,917 Points

Congratulations Ratik Sharma . Could you notify us here, when you publish your app on the play store.? Cheers!

Gianni Zamora
Gianni Zamora
9,547 Points

hey guys, i was not ready to jump into this challenge but are there any files or examples of code to help us build this project. I would love to learn how to do it.

Akshay Shivpuri
Akshay Shivpuri
2,917 Points

Hi Gianni, Here, Ben hass taught to make a weather forecast app using forecast.io api. http://teamtreehouse.com/library/android-data-storage-with-sqlite Check this out.

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference

how to fix it ???