Re: null pointer exception
Quote:
I cannot for the life of me figure out why I am getting a null pointer exception here.
Code:
gameBoard[i][k] = Variables.getButtons()[buttonLocator].getText();
There are quite a few things that could be null:
gameBoard
gameBoard[i]
gameBoard[i][k]
Variables.getButtons()
Variables.getButtons()[buttonLocator]
(Basically the NPE arises because you cannot "dereference" with [] or . something that has the value null.)
Use System.out.println() to display the value of each just before you get the NullPointerException.
-----
I'm assuming Variables is a class, otherwise you would have to check if it was null. Using static methods and variables is just asking for NPE and other troubles because anywhere in the code can clobber a perfectly good value with null thereby making looking for the *cause* of the NPE rather hard work.
[Edit] On second thoughts, it is static variables that are particularly nasty in this regard. But still, things shouldn't be static without some good reason.