Accordin到的调试屏幕的误差是在:为什么我得到一个数组索引越界异常?
1.Line 16:(类RandomLevel)
protected void generateLevel() {
for (int y = 0; y < height; y++) {
for (int x = 0; y < width; x++) {
tiles[x + y * width] = random.nextInt(4); //Here is the error.
}
}
}
2.Line 15:(职业等级)
public Level(int width, int height) {
this.width = width;
this.height = height;
tiles = new int[width * height];
generateLevel(); //Here is the error.
}
3。第10行:(类RandomLevel)
public RandomLevel(int width, int height) {
super(width, height); // Here is the error.
}
4. 43行:(类游戏)
public Game() {
Dimension size = new Dimension(width * scale, height * scale);
setPreferredSize(size);
screen = new Screen(width, height);
frame = new JFrame();
key = new Keyboard();
level = new RandomLevel(64, 64); // Here is the error.
addKeyListener(key);
}
5.Line 124:(类游戏)
public static void main(String[] args) {
Game game = new Game(); // Here is the error.
game.frame.setResizable(false);
game.frame.setTitle(game.title);
game.frame.add(game);
game.frame.pack();
game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
game.frame.setLocationRelativeTo(null);
game.frame.setVisible(true);
game.start();
}
那我该怎么办?我明白什么是例外,但我不知道它为什么出现。帮帮我?
仔细查看此条件为'(INT X = 0; y <宽度; x ++)',复制粘贴可能会导致问题有时 – 2015-03-30 18:29:13