Skip to content Skip to sidebar Skip to footer

Attempt To Invoke Virtual Method 'int Java.util.random.nextint(int)' On A Null Object Reference [android]

I'm trying to use the rng from java when I click a button but each time I click it the program crashes and gives me the following error: Caused by: java.lang.NullPointerException:

Solution 1:

private Random dice;

I don't see any code that initializes the dice variable before you use it in dice.nextInt(rollProgressMA);.

Just change the declaration to :

private Random dice = new Random();

Post a Comment for "Attempt To Invoke Virtual Method 'int Java.util.random.nextint(int)' On A Null Object Reference [android]"