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 Simple Android App (2014) Coding the Fun Facts Using an Array

Declare a String variable named lastSport and initialize it with the last element of the sports array.

Dont know where is my mistake. My code: String bestSport=""; String lastSport=""; String[] sports={bestSport, "Football", "Still Football", "Soccer", lastSport}; Thanks for the help

3 Answers

Made the mistake myself.

Take the variable bestSport out of the array!!!

Then you initialize it with:

<b>lastSport = sports[sports.length - 1];</b>

bestSport should be:

<b>bestSport = sports[0]; </b>

The problem is you assigned the variable lastSport to the end of sports array. You need to assign the value of the last element of the sports array to the variable lastSport. Here is a hint:

String firstSport = sports[0];
David Hope
David Hope
19,876 Points

You don't need to declare the Strings bestSport and lastSport individually since they will be stored in the string array. The first item in this array is what sets bestSport and likewise for the third item in the array. Good luck and happy coding, Simon!!!