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?

3
  • For what language? If it's Java, are you debugging with source? Commented Jan 9, 2014 at 8:32
  • @NEO , Did your problem solved?? Commented Jan 9, 2014 at 8: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. Commented Jan 9, 2014 at 9:29

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

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 } }
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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.