Well I just started coding in Java with seperate files and classes, and I believe this is an organization problem;
SOOOO I have 3 files:
All have 1 class and methods.
Here's one
public class runprogram { public static void main(String[] args) { runprogram run = new runprogram(); run.runprogram(); } public void runprogram(){ GetDataMethods f = new GetDataMethods(); Cell cell = new Cell(); cell.assignvalues(); System.out.println(cell.cellarray[4].value); } } }
Here's the other
public class Cell { int value; int xloc; int yloc; int possiblevalues[]; Cell[] cellarray = new Cell[81]; //Prints out values of Cell public void assignvalues(){ GetDataMethods g = new GetDataMethods(); Cell one = new Cell(); int currentnumber = 0; for (int row = 0; row <= 8; row++) { for(int col = 0; col <= 8; col++) { int x = 0; currentnumber = g.newboard[row][col]; one.cellarray[x] = new Cell(); System.out.println(one.cellarray[x].value=currentnumber); x++; } } } }
And here's my last one
This one has alot more methods I posted only the relevant part of it.
That's all dandy, however, I get a null pointer exception error if I try using the method assignvalues from Cell class, the file Cell, out side of file Cel.public class GetDataMethods { int emptycells[]; //The Sudoku int[][] newboard = {{0,0,0,0,6,0,0,0,9}, {0,6,0,0,0,0,3,0,1}, {2,0,0,0,0,9,8,0,0}, {1,9,6,0,0,2,0,0,8}, {0,0,0,3,0,8,0,0,0}, {8,0,0,9,0,0,1,7,5}, {0,0,1,7,0,0,0,0,4}, {6,0,7,0,0,0,0,8,0}, {4,0,0,0,9,0,0,0,0}}; //The Possible Values public int possibilityboard[][]; int value; }
Any idea what I'm doing wrong?
Basically, why do I get a nullpointer in runprogram?