Results 1 to 3 of 3
Thread: Null on 2D Array
- 03-22-2011, 06:57 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 2
- Rep Power
- 0
Null on 2D Array
I know this is probably a very simple solution, but im very new to Java... im just switching over from C
My problem is i get a "Null" exception on my gameOn 2D array in the display method... can anyone help?
The display is a method that supposed to print a 6 by 7 grid of X's with numbers 1 through 7 at the bottom
Thanks
Java Code:public class connect4 { // instance variables private String[][] gameOn; /** * Constructor for objects of class connect4 */ public connect4() { // initialise instance variables String[][] gameOn = new String[6][7]; } public void display() { for( int x = 0; x <= 5; x++) { for( int y = 0; y <= 6; y++) { gameOn[x][y] = "X"; } } for(int x = 0; x <= 5; x++) { int y = 0; System.out.println(" " + gameOn[x][y] + " " + gameOn[x][y+1] +" " + gameOn[x][y+2] +" " + gameOn[x][y+3] +" " + gameOn[x][y+4] +" " + gameOn[x][y+5] +" " + gameOn[x][y + 6]); } System.out.println(" " + 1 + " " + 2 +" " + 3 +" " + 4 +" " + 5 +" " + 6 +" " + 7); } }
- 03-22-2011, 07:01 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
remove the String[][] :DJava Code:public connect4() { // initialise instance variables String[][] gameOn = new String[6][7]; }
- 03-22-2011, 07:29 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Array null values
By blug in forum New To JavaReplies: 2Last Post: 03-20-2011, 06:48 AM -
Is it better to set array elements to null before setting the arrayreference to null?
By kreyszig in forum Advanced JavaReplies: 6Last Post: 10-18-2010, 10:40 AM -
How to get null values stored in array
By Ms.Ranjan in forum New To JavaReplies: 4Last Post: 05-21-2009, 10:29 PM -
help array set null or delete
By chkm8 in forum New To JavaReplies: 1Last Post: 01-19-2009, 08:15 PM -
Null array when passed to MouseListener
By stevemcc in forum New To JavaReplies: 2Last Post: 04-02-2008, 10:42 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks