This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I am writing a program for a class and I am having a weird issue with a constructor.
In my test program, I am trying to do the following:
The Room class is as follows:
Now the problem is that the first Room constructor in the test program is bringing back a NullPointerException while the second constructor is working just fine and returning the "Null Room Name" exception message. When I try to step through the test program, I get a "ClassNotFoundException" on the first Room constructor.
Yes. However you have put code in your catch-blocks which hides most of the exception's useful information. Replace that code by this:
and then you will get the full stack trace of the exception which was thrown. In particular you will see the line number from where the exception was thrown. That should help you zero in on the problem.
You don't need to explicitly set all array elements to null. Array elements default to 0 for primitive numeric arrays, '\0' for char arrays, false for boolean arrays and null for object arrays. After calling "exitRooms = new Room[MAX_EXITS];" all elements are already null.