Accordin к экрану отладки ошибки в:Почему я получаю исключение Array index out of bounds?
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: (Класс Game)
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: (класс Game)
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 х = 0; y <ширина; x ++) ', копирование может иногда вызвать проблемы –