0

random nextInt

My game crashes after this line --> velX = (random.nextInt(10) - 5); any ideas?

23rd Aug 2017, 3:33 PM
Ilias
Ilias - avatar
4 Respostas
+ 5
According to the documentation, nextInt only throws an IllegalArgumentException if the parameter is not positive. My guess is it that you are not calling it with a literal constant 5, but rather with some variable that happens to be zero (or negative). The exception was being thrown from another call to r.nextInt() on the same line which was taking an uninitialized variable as an argument!
23rd Aug 2017, 5:12 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 3
What was the error?
23rd Aug 2017, 5:20 PM
Rrestoring faith
Rrestoring faith - avatar
+ 3
If what @Gawen said wasn't your problem, I suggest using the debugger. Add some break points where it crashed and go through what the code is doing. Make sure there's no infinite loops.
24th Aug 2017, 1:49 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
"What was the error?" Something with Thread... game is running but when it's going to spawn mobs with this code it crashes. what should I do?
24th Aug 2017, 12:40 PM
Ilias
Ilias - avatar