1

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?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
NEO
  • 161
  • 1
  • 3
  • 10
  • For what language? If it's Java, are you debugging with source? – nitind Jan 09 '14 at 08:32
  • @NEO , Did your problem solved?? – gowtham Jan 09 '14 at 08:52
  • @gowtham Nopes... I am in the same scope of the method as that of local variable. and, Specifically I am debugging values under for-each loop. but, after setting Watch or Inspect, I get same error message. – NEO Jan 09 '14 at 09:29

4 Answers4

2

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.

Chandrayya G K
  • 8,719
  • 5
  • 40
  • 68
2

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.

SaurabhJinturkar
  • 554
  • 7
  • 20
  • I am in the same scope of the method as that of local variable. and, Specifically I am debugging values under for-each loop. but, after setting Watch or Inspect, I get same error message. Sample code for inspecting value of local variable "x" :- for(int x : G.adj[V]){ if(!marked[x]){ //perform some operations } } – NEO Jan 09 '14 at 08:49
1

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

gowtham
  • 977
  • 7
  • 15
0

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

user2518618
  • 1,360
  • 13
  • 32