I am creating Conway's Game of Life in android. I have what I believe to be a working engine, and I have a working initial grid view to which I can draw and populate points on the initial array. However when I attempt to pass the initial array into my game engine I am getting a null point exception. The code where I am attempting to pass the initial array is below:
case R.id.test_item:
{
Toast.makeText(getApplicationContext(),R.string.generation_string,
Toast.LENGTH_LONG).show();
myGridView.setStart(true);
char[][] testGen = myGridView.getWorld();
System.out.println("test1");
char[][] nextGen = lifeEngine.generateNextGeneration(testGen);
myGridView.setWorld(nextGen);
myGridView.invalidate();
}
public char[][] generateNextGeneration(char[][] world) {
System.out.println("test1");
//char[][] currentGeneration = world;
int neighbors;
System.out.println("test1");
char[][] nextGeneration = new char[height][width];
System.out.println("test1");
for (int c = 0; c < (height-1)/UpdateGridActivity.cell_size; c++) {
for (int r = 0; r < (width-1)/UpdateGridActivity.cell_size; r++) {
System.out.println("test1");
neighbors = checker.Check(world,c,r);
System.out.println("test1");
if(world[c][r] != 0) //handles live cells
{
//neighbors = checker.Check(world,c,r);
if (neighbors !=3 && neighbors !=2)
nextGeneration[c][r] = 0;
else
nextGeneration[c][r] = '*';
}
else //handles dead cells
{
//neighbors = checker.Check(world,c,r);
if(neighbors == 3)
nextGeneration[c][r] = '*';
else
nextGeneration[c][r] = 0;
}
}
}
return nextGeneration;
}
}
The first "test1" appears in my logs, but the app crashes and the null pointer exception is thrown before the next "test1" at the top of generateNextGeneration is printed out. At this point I cannot figure out where the exception is coming from, as I am not sure how the header would throw it.
In case you would like to reference it, my entire source code can be found at: https://umbc.box.com/s/m7elds5u7120tysiwplzma3t4lgef69w