How to use debug in Eclipse?

20

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

25

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:

Therewillbeablueball.Then,insteadofclickingthewhitearrowinsidethegreencircletoruntheprogram,clickonthebugtoyourleft.

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.

ClickYes.Ifyouprefer,selectthecheckboxtoremindyouofyourchoice.

Whenevertheexecutionencountersabreakpoint,itwillbemomentarilyinterruptedandyoucanseethecontentsofthevariablesatthattime.

Toseethecontentsofthevariablesyoucanhoverthecursoroverthenameofeachvariable,oryoucanalsoaddthemtotheExpressionswindowtoseethecontentsofseveralvariablesatthesametime.Toaddavariabletothiswindow,selectthevariableandright-clickonit,thenclick%with%.

She will appear like this:

Fromthemomentyourunabreakpointyoucancontinuetorunline-by-line,youcanentermethods,orevenexitmethods,fromofthen.Therearecorrespondingoptionsinthetaskbar.Seebelow:

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