Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Simple Android App (2014) Coding the Fun Facts Using an Array

Pedro Menezes
Pedro Menezes
377 Points

Cannot find symbol

JavaTester.java:66: error: cannot find symbol int numberOfSports = randomGenerator.nextInt[sports.length]; ^ symbol: variable randomGenerator location: class JavaTester 1 error

I didn't understand why it doesn't works. Can anyone help me?

Ty

Array.java
String[] sports = { "Basketball", "Baseball", "Tennis" };
String bestSport = "Basketball";
int numberOfSports = randomGenerator.nextInt[sports.length];

1 Answer

cm21
cm21
150,854 Points

Hi Pedro,

There is no randomGenerator variable in this task, and there is no need for the compiler to look for an integer to be entered: you simply need to set the integer number of sports to the length of (the number of elements in) the sports array.

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

Hope this helps!