Android Build a Simple Android App Basic Android Programming Generating a Random Number

David Hume
David Hume
9,581 Points

I'm getting this error when I try to run my code: Error:(35, 55) error: package randomGenerator does not exist

Here's the code: public void onClick(View v) { //the button was clicked - update TextView with new fact String fact = ""; //RANDOMLY SELECT A FACT //first IMPORT class: Random randomGenerator = new Random(); //create variable to store randomly generated number: int randomNumber = new randomGenerator.nextInt(3); fact = randomNumber + ""; //update screen with dynamic fact

            mFactTextView.setText(fact);
        }
    };

2 Answers

Kourosh Raeen
Kourosh Raeen
23,707 Points

Do you have the following import statement?

import java.util.Random
David Hume
David Hume
9,581 Points

I found my mistake. Typo. Had an extra "new" in code.