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

Java Array

I got started on the array and i always mess up on them. I did the string of bestSport

String bestSport = sports []

and it says a Syntax error

4 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Matt,

You're very close to the correct answer, the challenge task is asking you to select the first item from the sports array and if you remember arrays always start at the index 0 therefore we can simply target the value Basketball by using the index 0.

String bestSport = sports[0];

Happy coding.

Nicholas Romano
Nicholas Romano
3,223 Points

To initialize a string array with a set size use

String bestSports[] = new String[20];
// 20 being the length of the array to initialize
Stone Preston
Stone Preston
42,016 Points

your second example does not intialize the array, it just declares it. You cannot initialize an array without a fixed size in java.

Nicholas Romano
Nicholas Romano
3,223 Points

Good point, just edited it thanks!

Odd, doesn't seem to work when I enter it in. I tired doing the == and taking out the number but it still says syntax error.

Hi Matthew,

Try this:

String bestSport = sports[0];