Okay, you have another (big) problem: When you name a parameter of a method the same as an instance variable of that class, the parameter variable "hides" the instance variable. So, in this snippet of code, for example:
public class GridNode
{
private int[][] state;
...
public void moveRight(int[][] state) {
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 3; col++) {
if (state[row][col] == 0) {
state[row][col] = state[row][col+1];
state[row][col+1] = 0;
return;
}
}
}
}
...
} The state
parameter, not the state
instance variable, is being changed! As you can image, all sorts of problems will arise. (The original array, presumably declared in NewMain, will be altered, for the reasons described in my last post.) The solution: Either don't name any of your parameters the same as any of your instance variables or use the this keyword to qualify variables:
this.state[row][col] = state[row][col+1];
All that said, however, this is not the cause of your problem--and perhaps you intended that behavior. If so, the method should be declared static (and you might want to consider changing the parameter name anyway for obvious reasons).