I am now getting a "NullPointerException at Game.checkBox(Game.java:211)". I believe that this due to the statement "if (rect [i].contains(p)) grid = i + 1;". I am not sure whether I need another "this." on what? Still trying for that deadline. My code follows:
[This message has been edited by Marilyn deQueiroz (edited October 09, 2001).]
Uhhh, what have you done to the code ? You have massacred it. I cannot help you if you do not listen to the advice...... you now seem to have braces (curly brackets) floating randomly all over your code.
Its not what you do, its the way you say you've done it.
You also seem to have declared variable "rect" of type Rectangle  TWICE !
posted 18 years ago
In the init() method you do not need to declare the type of variable "rect" again, only that it has 9 entries, thus:
You seem to be numbering the grids 1 to 9, and then using this number as an index into the array "move". Java numbers the array 0 to 8! So no wonder you are getting all kinds of errors. In method checkBox() decide how you are going to set up the variable "grid". It's also worth mentioning that when looping through an array it isn't good practice to use a number (e.g. 9), use "arrayName.length" (e.g. rect.length) instead. That way if the number of entries in an array ever changes the existing code will still check all entries and you won't be in danger of 'missing' a line of code that you should have changed. Perhaps a quick refresher through the online Java tutorial would be of benefit here. Remember it's a lot easier to write good code to start with than to debug bad code later on. Good luck.