Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information. Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.
I've gone ahead and added the code tags for you. See how much easier the code is to read?
It's bad practice to catch a NullPointerException. You need to fix your code so that you won't get a NPE, either by checking for null before using an object reference or by ensuring that the reference will never be null by initializing it to something.
Matthew Brown wrote:Not as bad as just catching Exception .
Yeah, that's BAD too.
This kind of code is a cop out at best and a sign of programmer laziness at worst. In both cases, it's the programmer's responsibility to do more than just add a catch block. Take the effort to fix the code that causes a NullPointerException. Take time to analyze the code and identify the exact subclass of Exception that can be thrown, then decide whether or not there is something you can do to recover from the problem.