Android Build a Simple Android App Basic Android Programming Using the Random Class

Filip Stefanovski
Filip Stefanovski
2,371 Points

Don't know what to do here.

Tried declaring randomGenerator (Random randomGenerator = new Random ();) I also used int randomNumber = randomGenerator.nextInt (); .

RandomTest.java
Random randomGenerator;
int randomGenerator = new Random ();

2 Answers

You might be on the second task? The code I posted will pass the first task of the challenge.

From memory, the second task requires you to create a new int variable called randomNumber and to use the nextInt() method on the `randomGenerator instance with no range set. Correct?

That looks like:

Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt();

Is that where you are at?

Steve.

Filip Stefanovski
Filip Stefanovski
2,371 Points

I am still on the first task aka ("Initialize a new Random variable called randomGenerator. Hint: Don't forget to use the new keyword.") . Tried the ( Random rendomGenerator = new Random (); ) doesn't work think its a bug. while using this code there is a compiler error that states "JavaTester.java:65: error: variable randomGenerator is already defined in method run() Random randomGenerator = new Random () ; ^ 1 error" there is most likely a bug preventing me from goin forward. Also tried using incognito mode since I was told my plugins in chrome might affect the compilers in the worbenches.

You typed randomGenerator wrong in that. The first task is as I explained above:

Random randomGenerator = new Random();

No brackets around it, just as it looks there.

Filip Stefanovski
Filip Stefanovski
2,371 Points

Thank you a ton steve! I just found out what the problem was it wasn't the code but I had to delete the text that was written by default aka ( Random randomGenerator; ), when deleted I passed just fine but since I didn't have to do that in the exercises till now I hadn't had a clue that the aforementioned text would cause a compiler error when not deleted. Well in any case this should be fixed so that people wouldn't get stuck for so long just like I did. Thanks again!

Hi Filip,

There's no requirement to delete the code that the challenge gives you. I have no idea what issue you had there.

I will have a look at your code in more detail.

Steve.

Hi Filip,

The challenge comes with a Random sized variable waiting for you to store your new Random() in. You've got that bit of code, so just assign it into the existing variable either on a new line (delete the keyword int) or all in one line:

Random randomGenerator = new Random();

I hope that helps ,

Steve.

Filip Stefanovski
Filip Stefanovski
2,371 Points

Thanks for the response . I tried doing that and it didn't work, also tried adding ( int randomNumber = randomGenerator.nextInt (); ) although that didn't help at all. There might be a bug with the engine or another way to do this, still the video didn't show me any other way :P. Have been trying multiple things still to no avail.