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

Abhishek Gangadhar
Abhishek Gangadhar
9,467 Points

Don't Understand why I'm getting an error here... I need to allot the value of the length of an array to an integer

String bestSport = "Crcket"; String[] sports = { bestSport, "Baseball", "Tennis" }; int numberOfSports;

numberOfSports=sports.lenght;

Array.java
String bestSport = "Crcket";
String[] sports = { bestSport, "Baseball", "Tennis" };
int numberOfSports;

numberOfSports=sports.lenght;

1 Answer

Hi there,

Here's the code for that part of the challenge.

Firstly, when you are declaring a string variable and storing the first array element in it, that should be done by accessing the array. econdly for you int variable, you need to declare it as such first (you can do this on one line), then use the length property (check your spelling).

String[] sports = { "Basketball", "Baseball", "Tennis" };
String bestSport = sports[0];
int numberOfSports = sports.length;

I hope that helps.

Steve.

Abhishek Gangadhar
Abhishek Gangadhar
9,467 Points

Wow thanks lot Steve :) I'm amazed at hope fast i got help here :)

Hey, no problem! There's usually someone looking at the forum trying to help people out.

:-)

Steve.