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
Varun Kashyap Kuturu
17,963 Pointsmy code broken ... need some help
when ever i add the
String[] anewone ={
"stuff"'
};
my fact and randomNumber are considered as an unknown class how do i fix it and i am getting this error Error:(42, 17) error: <identifier> expected
here my code
String [] anewone = {
"Ants stretch when they wake up in the morning.",
"Ostriches can run faster than horses.",
"Olympic gold medals are actually made mostly of silver.",
"You are born with 300 bones; by the time you are an adult you will have 206.",
"It takes about 8 minutes for light from the Sun to reach Earth.",
"Some bamboo plants can grow almost a meter in just one day.",
"The state of Florida is bigger than England.",
"Some penguins can leap 2-3 meters out of the water.",
"On average, it takes 66 days to form a new habit.",
"Mammoths still walked the earth when the Great Pyramid was being built." };
};
String fact = "";
Random Randomgenerator = new Random();
int randomNumber = Randomgenerator.nextInt(anewone.length);
fact = anewone[randomNumber];
textView.setText(fact);
}
};
2 Answers
Steve Hunter
57,712 PointsHave you tried declaring your array, which is a member variable, as public? You may have some scope issues there - it is hard to tell without seeing all the code.
I can't immediately see anything else that could cause a problem with the code. Give that a try and let me know if it worked.
Steve.
Steve Hunter
57,712 PointsThe curly braces look strange to me. The one after the textView.setText() line closes the class, presumably? What's the next one with a semi-colon doing?
Can you post the whole file, please?
Varun Kashyap Kuturu
17,963 Pointsits fixed thanks i accidentally added two }} after listing the values in the string
Steve Hunter
57,712 PointsSo you did! Sorry - I should've spotted that.
Glad you're up and running!
Steve.