![]() |
|
#1
|
|||
|
|||
NullPointerException in JavaCan somebody please help me figure out why the following code compiles but gives an error message when I try to run it. The txt file "home.txt" that I'm trying to read it into array contains the numbers bellow. The first row is the size of the array (dimension) i.e this is a four row four col. while the subsequent rows are blocked cells i.e {0,1},{1,3} {2,0}and{2,2}.
I'm guessing the array has some null cells but can't figure out cause I have already declared and initialized. Thanks "home.txt" file Code:
Error message: Code:
JAVA Code:
Last edited by admin : 21-Feb-2009 at 07:23.
Reason: Please insert your example Java codes between [JAVA] and [/JAVA] tags
|
|||
|
#2
|
||||
|
||||
Re: NullPointerException in javaIt appears that two mazes are created?
One here: JAVA Code:
JAVA Code:
JAVA Code:
Now to the original problem... Java is typically very good about pinpointing the problem area, but one needs to understand where it complains to be able to determine the problem...so lets follow the runtime stack-dump that you were given: Code:
File Game.java, line 21 ==> inside main(), statement calling createMaze() File Game.java, line 46 ==> inside createMaze(), statement calling new Maze() File Game.java, line 143 ==> <init> [implies the constructor] at this statement, complaining about the null: JAVA Code:
Even though you have declared a 4x4 array of Cells as: JAVA Code:
So to fix that, just after the declaration, the array needs to be populated with Cell objects, like so: JAVA Code:
Post another reply if you have more questions, or need more help. __________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#3
|
|||
|
|||
Re: NullPointerException in javaThanks a lot, Thas was the problem. I populated the array and corrected a few thigs
Msafi |
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What is the equivalent in Java for a Function or Module in VB | pengwinz | Java Forum | 2 | 17-May-2007 20:02 |
| To post messages / click Buttons of a Java Jar App using code | Jun0 | C Programming Language | 1 | 06-Jan-2007 14:44 |
| To post messages / click Buttons of a Java Jar App using code | Jun0 | Java Forum | 0 | 06-Jan-2007 11:14 |
| Sun Java Wireless Toolkit | JdS | Java Forum | 0 | 23-Mar-2006 06:16 |
| Scalability in Java and C++ | agx | Miscellaneous Programming Forum | 7 | 04-Feb-2006 15:35 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The