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 (retired 2014) Learning the Language Objects and Random Numbers

Bummer! Check the parameter you're using for 'nextInt()'. Hint: 0 through 9 is a total of 10 choices.

this is the error I keep getting in this is my code what am I doing wrong?

Random randomGenerator = new Random();//Constructa new Random number generator int randomNumber = randomGenerator.nextInt(1)

3 Answers

Stone Preston
Stone Preston
42,016 Points

you need a generate a number between 0 and 9. you are currently only generating a number between 0 and 1 exclusively (so only 0 will be generated)

if I wanted to generate a number between 0 and 5 I would use

int randomNumber = randomGenerator.nextInt(6);

I tried that i went threw every number between 0 and nine it still gave that error

Stone Preston
Stone Preston
42,016 Points

the number you pass to the method is exclusive. you said youve tried 0 through 9, try using 10.

thanks it worked