How to use debug in Eclipse?


I'm having a very annoying problem with a java.lang.NullPointerException error and I want to know if with debug it shows which element is null, rather than just saying what line the error is in.

asked by anonymous 09.02.2014 / 00:10

1 answer


First, mark a breakpoint in the line of code that you have the problem with. In your case it's in the line 34 , correct? :)

To enter breakpoint give two clicks on the left side of the line number indication:


Your program will run normally until the execution reaches a line that is marked with a breakpoint . If it is the first time running in debug mode, Eclipse will ask you if you want to change the perspective for Debug, as shown below.




She will appear like this:


Clicking on the first symbol, which is the green arrow, you will pass the command for your program to run until you find another breakpoint . The red square completely stops the execution of your code. The first yellow arrow (whose shortcut key is F5) will execute line by line of your code entering the methods when there is one, including changing the screen to show the corresponding class, I believe this may be a good option for your case . The second yellow arrow is when you want to run lynch by lines but without getting into a method when you find one. The last yellow arrow is the option to drop out of the current method.

The console will give you more details when the exception occurs, keep an eye out and good debug .

09.02.2014 / 00:36