Tim Harris wrote:If you're using an IDE, you can debug it and take a look at the different calls to see where you might be getting a null pointer exception - set up a few breakpoints where you're calling getNextSibling or getAttribute or getX, and see what those calls are returning.
If you're not using an IDE you can drop comments in using System.out.println to see where the call is failing.
Ana-Maria Salai, just for a general information:
If you're not using IDE, you still can use debugger - the one which comes along with JDK. It calls "jdb" -
Java debugger.
It could be difficult and crazy to get start with it, as it would require to research a bit how to use it and understand it, but at the same time it could be funny to discover some tools included to JDK.
Quick basics:
1. When you compile your source code, you'd need to use -g option, so all debugging information would gets generated (class file would be slightly bigger than usual without -g option)
"javac -g ToDebug.java"
2. In order to start debugging, you could execute Java debugger by writing in terminal (unix like os) or commander (windows):
"jdb ToDebug"
3. Then you could set up breakpoint in the same way as you'd set up in IDE:
"stop at ToDebug:line-number" for example "stop at ToDebug:6"
After successfully set up break point,
you should see similar message to:
"Deferring breakpoint
Test:6.
It will be set after the class is loaded."
4. Then next step to execute debugging process:
"run"
5. At this point you should type "help" and search for an appropriate command: either you want to print local variables, or step into the function, or step over.. et cetera.
For more information from the very beginning you could find by typing "man jdb" (unix like os) in windows don't know how to access help. Maybe "jdb help" in commander.
It could be a funny challenging weekend's attraction though