0

I ran a program and received an null pointer exception. I added a Java Exception breakpoint and debug. For example, it broke at line 11 in a method called "myMethod". On line 11, it shows that the object "Box" is null in debuger. From here, how can I step back to trace the root of the cause? I think the problem occurs outside of the method "myMethod", because the object Box is passed as a parameter of the method and is shown as null.

Thank you.

marlon
  • 6,029
  • 8
  • 42
  • 76
  • Duplicate question, answered here - http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it – Andrew Williamson Feb 17 '16 at 22:25
  • 1
    Why would you need to step back? Read your code... where is Box declared? Unless you have some complicated mutlithreaded app, and judging by this questions, im going it assume it isnt, then your program can only take one path to where you are at. If box was never initialize then there you go. – user1231232141214124 Feb 17 '16 at 22:25
  • @redFIVE, Box is defined outside and passed as a parameter to this method. So in this method, there is no way to know why it becomes null. – marlon Feb 17 '16 at 22:30
  • what do you mean outside? Set a breakpoint on box declaration and follow it from there. If your program never hit that breakpoint then you have your answer – user1231232141214124 Feb 17 '16 at 22:32
  • outside of the method in which exception occurs. So I need to set a new break point from where the Object is defined? So you need several iterations to find the proper break point to set and therefore you need to start and shutdown the debugger for a few times to get where you are. Right? – marlon Feb 17 '16 at 22:34

1 Answers1

3

You should see a stacktrace in the tab called "Debug" in the debug view. When you hit the breakpiont in myMethod, go to the stack trace in the debug view and click on the previous method in the stack trace and look at the value.

SomeDude
  • 13,876
  • 5
  • 21
  • 44