Results 1 to 5 of 5
- 11-08-2008, 04:45 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 17
- Rep Power
- 0
[SOLVED] Help with understanding nullpointexcepion
I am new to java and I am having some problems with nullpointexception. This is the first time I have encountered this problem so I would love any help in resolving it/helping me understand why I am getting this error would be appreciated.
Last edited by soxfan714; 11-11-2008 at 04:01 AM.
-
A NPE is telling you that you are trying to "dereference" or use an object that has not yet been initialized, that is set equal to null. To figure out which object this is, you need to look at the line that's throwing the error and then test each object there to see what is set to null. The line that I see causing this is:
To find out which object is at fault, use a poor-man's debugger, the System.out.println statement. I changed your code to read:Java Code:myFloors[s].unloadPassengers(s);
Java Code:private static void stop(int s) { System.out.println("\nStoping on floor " + currentFloor); System.out.println("myFloors == null: " + (myFloors == null)); System.out.println("myFloors[s] == null: " + (myFloors[s] == null)); myFloors[s].unloadPassengers(s); }
-
Now you have to figure out why this error is being thrown. So if you look at the myFloors variable, you'll see that it has been initialized properly here:
but where are the myFloors items that are held by the array being initialized? In other words if there are 4 items in the array, where are myFloors[0], myFloors[1], myFloors[2], and myFloors[3] being initialized? No where.Java Code:static Floor[] myFloors = new Floor[FLOORS];
- 11-11-2008, 04:00 AM #4
Member
- Join Date
- Nov 2008
- Posts
- 17
- Rep Power
- 0
Thanks that worked.
-
Similar Threads
-
Understand my logic errors and better understanding method and class creation
By freethinker89 in forum New To JavaReplies: 3Last Post: 10-06-2008, 11:03 PM -
Understanding Vectors
By cbrown08 in forum New To JavaReplies: 7Last Post: 11-05-2007, 06:56 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks