Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netbeans: How do I break on a NullPointerException?

When debugging a java program in netbeans, I want the debugger to stop on the line that causes a NullPointerException so I can examine the variables there. I believe I have to use a condition on the breakpoint set at that line, but what is the syntax of the condition?

thanks for the help

like image 703
D.C. Avatar asked Apr 19 '10 18:04

D.C.


People also ask

How fix NullPointerException in Netbeans?

In Java, the java. lang. NullPointerException is thrown when a reference variable is accessed (or de-referenced) and is not pointing to any object. This error can be resolved by using a try-catch block or an if-else condition to check if a reference variable is null before dereferencing it.

How do I stop NullPointerException?

To avoid the NullPointerException, we must ensure that all the objects are initialized properly, before you use them. When we declare a reference variable, we must verify that object is not null, before we request a method or a field from the objects.

How do I remove a breakpoint in Netbeans?

Select menu Window / Debugging / Breakpoints (or press Alt + Shift + 5 ), then right-click in the Breakpoints window and select Delete All.


1 Answers

Go to debug > New Breakpoint (alternatively CTRL+SHIFT+F8). Change the breakpoint type to Exception in the top right hand drop down menu. Type java.lang.NullPointerException in the Exception class field. Choose whether to break on caught, uncaught or both.

Debug your code and watch the glorious auto breakpoint when the Exception is thrown.

like image 175
Finbarr Avatar answered Oct 10 '22 10:10

Finbarr