NEO
NEO

Reputation: 171

How to check local method variable while debugging using eclipse IDE?

I am debugging my code using Eclipse IDE. But, problem is I am not able to check values in the local method variables. When I do right click on the local variable and inspect that I get an error as variable cannot be resolved.

What do I do to see values in those variables?

Upvotes: 1

Views: 5986

Answers (4)

user2518618
user2518618

Reputation: 1407

This is similar to this question: you cannot watch or inspect the variables, because you didn't compile the class with debug information. You have to add the -g option to your javac command

Upvotes: 0

gowtham
gowtham

Reputation: 987

It is because of the scope of the variable.
And it all depends on where your control is while debugging,

If your control is in the method, then when you inspect you will be able to see the value, like this

enter image description here

And if your control is not in that method and if you try to inspect the value, then you see variable cannot be resolved, as shown below

enter image description here

Upvotes: 1

Chandrayya G K
Chandrayya G K

Reputation: 8849

Open Variables view in Eclipse. Click on Window->Show View->Other and type Variable in search box.

enter image description here

Note that local variables are marked as "L" symbol.

Upvotes: 2

SaurabhJinturkar
SaurabhJinturkar

Reputation: 554

Add a breakpoint to the method you want to debug. You can not check local variable unless you are in the method. As local variables have scope of the block of the method, they will be inaccessible unless method is executing and thus you are getting "variable can not be resolved" message.

You can add a watch by selecting variable and right click->watch to directly see variable value in Expressions view in debug perspective.

Upvotes: 2

Related Questions