Cześć nie wiem co jest grane testuje chcę wyświetlić tablicę i wywala błąd :
run:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at tester.Tester.main(Tester.java:67)
0 0 0 -1 0 0 0 -1 0 0 C:\Users\Tomek\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
kod:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tester;
import java.awt.Container;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
/**
*
* @author Tomek
*/
public class Tester {
private JButton StartGameButton;
private JButton Results;
private JMenuBar Menu;
private JMenu menuFile, menuHelp;
private JMenuItem iNewGame, iInformations, iShowResult, iClose;
private JButton[][] buttonsField;
private JPanel p;
private Container grid = new Container();
private static int[][] gameFiled;
private static int randomX, randomY;//do przechowywania wsp losowych min
public static void RandomPlace(){
Random rand = new Random();
randomX = rand.nextInt(10);
randomY = rand.nextInt(10);
}
public static void MinesPlaces(){
gameFiled = new int [10][10];
int numbersOfMines = 10;
while (numbersOfMines > 0){
RandomPlace();
if (gameFiled[randomX][randomY] == -1){
MinesPlaces();
}
gameFiled[randomX][randomY] = -1;
numbersOfMines--;
}
}
public static void Tablica(){
for(int i=0; i< gameFiled.length; i++){
for(int j=0; i< gameFiled[i].length; j++)
System.out.print(gameFiled[i][j]+" ");
System.out.println();
}
}
public static void main(String[] args) {
RandomPlace();
MinesPlaces();
Tablica();
}
}