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

code challenge .Initialize a new Random variable called randomGenerator using the Random() constructor.

Initialize a new Random variable called randomGenerator using the Random() constructor.

RandomTest.java
Random randomGenerator;

Did you have any issues with this? What was the error you got when trying it?

thank you

thank you

Dylan Merritt
Dylan Merritt
15,682 Points

So in the code that you posted, you have declared an instance of the Random class. This is basically telling the computer, "Hey, I'm going to use the Random class, and I'm going to name this usage of it randomGenerator." However, the computer doesn't quite know what that means. It knows you will be using the Random class, but it doesn't know what exactly what to do with that information. So what you say next is "randomGenerator is going to generate a random number." So your code should look like this:

Random randomGenerator = new Random();

Good luck.

1 Answer

They are asking to create a new Random variable using the Random() constructor so:

Random randomGenerator = new Random();