Friday, 6 September 2013

Array index out of bounds? How?

Array index out of bounds? How?

Hello good people of stackoverflow! I have a weird problem that I can't
understand. I'm gonna post my two methods that are problematic:
private static void resi(int [][] matrica,int row, int col) {
if (matrica[row][col] != 0) {
next(matrica,row, col);
} else {
for (int num = 1; num < 10; num++) {
if (checkRow(matrica,row, num) && checkColumn(matrica,col,
num) && checkBox(matrica,row, col, num)) {
matrica2[row][col] = num;
matrica4[row][col] = num;
next(matrica,row, col);
}
}
matrica[row][col] = 0;
}
}
And the other one:
private static void next(int [][] matrica2,int row, int col) {
if (col < 8) {
resi(matrica2,row, col + 1);
} else {
resi(matrica2,row + 1, 0);
}
}
So, I'm making a sudoku solver based on some code I found online. Now,
when I try to debug the program I can go over some of the lines nicely
(and it works as expected) but once the program first reaches the call for
"next" method in the method "resi" it crashes with array index out of
bounds exception. If I just try to run the program without debugging I get
a lot of "array index out of bounds" exceptions in the output tab of
NetBeans on the same method calls over and over again.
I don't know what's causing that error. As far as I can tell, row and col
aren't exceeding the 0-8 range... It must be a problem with the 2D arrays?
Thank you for your time.

No comments:

Post a Comment