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 trialzlatko divjakovski
874 PointsCannot resolve symbol 'facts'
It seems to me, that everything is equal like in the video, but it doesn't recognize automatically facts, and nether the length. Can anyone please help me? Thank you :) String fact = ""; //Randomly select a fact Random randomGenerator = new Random (); // Construct a new Random number generator int randomNumber = randomGenerator.nextInt(facts.length); /*Convert the randomNumber to a text fact *0 = Ants stretch when they wake up in the morning. * 1 = Ostriches can run faster then horses. * 2 = Olympic gold medals are actualy made mostly of silver.
*/
//if randomNumber equals 0 then
fact = facts[randomNumber];
//Update the label with our dynamic fact
factLabel.setText(fact);
}
};
showFactButton.setOnClickListener(Listener);
1 Answer
lambda
12,556 PointsIt says "missing symbol" because you don't have a "facts" array. There might have been a problem when you were copy-pasting the code or might be confusing "facts" with the String variable "fact" which contains an empty string.
zlatko divjakovski
874 Pointszlatko divjakovski
874 PointsThank you very much for your quick answer, and I'm sorry I wasn't able to answer sooner. I've checked, but I think that everything is ok with the "facts" array: { String[] facts = { "Ants stretch when they wake up in the morning.", But, down there, where I should write again> int randomNumber = randomGenerator.nextInt(facts.length); ... facts isn't recognized. I'm doing everything, like it's shown on the video, but on the video facts.lenegth gives automatic suggestions, and in my case gives back an error :(.