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) Basic Android Programming Using the Random Class

Declare an int variable named randomNumber and, without setting a range, use the randomGenerator variable and its nextIn

int randomNumber = randomGenerator.nextInt(); its telling me its not the answer

RandomTest.java
 int randomNumber = randomGenerator.nextInt(); 

1 Answer

MUZ141063 Erick Chapupa

Well it seems seeing only a single line, I expect that it gives errors. The errors will relate to the fact that the randomGenerator object is never instantiated. You immediatly declare and assign it to a value of something that does not exist ( at the moment).

The task from task 1 should be taken with it. Meaning that the code should include a declaration.

Random randomGenerator;
//the randomGenerator will need to get the methods 
//that belongs to the Random object. You need it to make it a new instance somehow. 
//Look at the task 1 text to see how itΒ΄s done ;p.

//Also if you want to know why, the nextInt belongs to the 
//Random object. If it is not of this type, java won't accept it or 
//recognize that it has these methods.

hope this helps !

if you have more questions, add my in your question by using the "@" char.