I have a very simple question but i can't figure out why I'm having this exception. I'm trying to create a 2-dimensional Array of objects for a sudoku puzzle, but when I'm initializing i'm getting ArrayIndexOutOfBoundsException. Please help, I've read similar questions and it should be working!
Here I'm declaring the grid(2-dimensional array of objects used and constructor):
public class Sudoku extends javax.swing.JFrame {
private int lines;
Cell[][] grid;
public Sudoku() {
initComponents();
grid = new Cell[lines][lines];
So when i'm cliking a button to set the lines(size length) as shown below
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
lines=10;
makeGrid(lines);
}
I'm getting the exception:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
at Sudoku.makeGrid(Sudoku.java:146)
public void makeGrid(int size) {
for(int i=0;i<size;i++)
for(int j=0;j<size;j++) {
146: grid[i][j] = new Cell();
}
}