I keep getting a null point error on the setter.
I tried to fix it by setting every point of the array to zero, but it still didn't work.
Please help.
public class SudokuArray {
public int[][] sArray;
public int falsecheck = 0; //used as invalid/valid check
public SudokuArray()
{
int[][] sArray = new int[9][9];
for (int i=0; i<9; i++)
for (int x = 0; x<9; x++)
sArray[i][x]=0;
}
public int[][] getArray()
{
return sArray;
}//end array getter
public void setValue (int value, int column,int row)
{
sArray[column][row] = value;
}//ends setter
public void Check()
{
//row checking
for (int i = 0; i<9; i++)//decides which row
{
for (int x=0; x<9; x++)// decides first point
{
for (int y=0; y<9; y++) //decides second point in row
while (x != y && sArray[i][x] != 0 && sArray[i][y] != 0)// makes sure each point isn't zero (null)
{ // and making sure its not comparing a point to itself
if (sArray[i][x] == sArray[i][y])
falsecheck = 1;
}
}
}//ends row check
it cut off the code so here's the rest of that class.
//column checking
for (int i = 0; i<9; i++)//decides which column
{
for (int x=0; x<9; x++)// decides first point
{
for (int y=0; y<9; y++) //decides second point in column
while (x != y && sArray[x][i] != 0 && sArray[y][i] != 0)
if (sArray[x][i] == sArray[y][i])
falsecheck = 1;
}
}//ends column check
//3x3 square check
for (int a = 1; a<4; a++)// check which column the square is in
{
for (int b = 1; b<4; b++) // check which row the square is in
for (int i = 3*a-3; i< 3*a; i++) //which row 1st point
for (int x = 3*b-3; x< 3*b; x++) //which column 1st point
{
for (int j = 3*a-3; j< 3*a; j++) //which row 1st point
for (int y = 3*b-3; y<3*b; y++)
while (sArray[i][x] !=0 && sArray[j][y] !=0)
while (j != i || y != x)
if (sArray[i][x] == sArray[j][y])
falsecheck = 1;
}
}//ends 3x3 square check
}//ends check
public int getCheck()
{
return falsecheck;
}// ends getter
}//ends class
import java.util.Random;
public class SudokuMain {
And Here is the main method.
public static void main(String[] args)
{
SudokuArray Sudoku;
Sudoku = new SudokuArray();
Sudoku.getArray();
Random rand = new Random();
int column,row,value;
int Amount = rand.nextInt(15) + 15;
for ( int i= 0; i < Amount + 1; i++) // to assign each variable
{
column = rand.nextInt(9); // assigns random column
row = rand.nextInt(9); //assigns random row
do {
value = rand.nextInt(9); //assigns random value
Sudoku.setValue(value,column,row); //actually sets the value
Sudoku.Check();
} while (Sudoku.getCheck() == 1);
}
}
}