From the course: Java's Toughest Bugs

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Debugging steps

Debugging steps

- Let's find the source of the null data. In the last case, it was pretty obvious because we set list E directly to null. Let's look at another example. Here in the main method, we create a new user with the name Catherine. The user class has name and address attributes. The name is set in the constructor, and the address can be set with the setter method. Going back to the main method, we retrieve the user city from their address and display it in the console. Let's run it. In the console, we get a null pointer exception when we access the city from the address. This happens because the address is null. It's important to note that this error occurs when we invoke a method on the null address attribute, not when the address attribute becomes null. Let's use the debugger and determine where the data for the user instance gets set. We'll put a breakpoint on the line where we create the user. Let's step into the execution…

Contents