I recently found the source and resource files to a JavaME version of Battle City which I was excited to put on my phone. After loading up Sun’s Wireless Toolkit 2.5.2_01 for CLDC, I went to build and received this error.
C:\Users\John\j2mewtk\2.5.2\apps\BattleTank\src\Tank.java:259: nextInt() in java.util.Random cannot be applied to (int)
int position = spawnPoints[rand.nextInt(numSpawns)];
Now I am no slouch when it comes to Java, so I figured I could fix it myself. These are my theories and attempts:
- Check all variables. spawnPoints[] is an array of integers, rand is a Random, numSpawns is an integer. - Yup
- Check if Random.nextInt(int) exists: http://java.sun.com/javame/reference/apis/jsr118/java/util/Random.html#nextInt(int) - Yup
- Check if WT is building using jsr118 (MIDP 2.0) - Yup
- Test if nextInt(int) is working at all by passing a negative numSpawns into the function and seeing if it results in an IllegalArgumentException as anticipated. - No, I am given the same exception with the same message, only -numSpawns passed to nextInt(int).
- Place a different argument into nextInt(int) like 8. - Once again the same is displayed only with rand.nextInt(8)
- Hulk Smash. - Yup
The function should exist, yes import java.util.Random; is there
If there is something I have overlooked, please feel free to call me an idiot.