Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot see final variable content inside anonymous class when debugging in Eclipse an Android app

When in debug (eclipse), I cannot see variables content in the variables view, nor in Expressions view, nor in Display view - if the variables are defined outside an anonymous class but the debug is inside the anonymous class.

When I try to see the content in debug, I get the error: x cannot be resolved to a variable.

In the following example, x cannot be resolved:

private void someMethod(final Object x) {
  new Runnable() {
    public void run() {
      Log.i(x); // x is printed correctly but cannot be resolved when in Debug
    }
  }.run();
}

This question regards the eclipse development environment - regarding debugging Android. It's not a discussion about final, nor compilation - just debugging.

like image 784
AlikElzin-kilaka Avatar asked Sep 19 '12 14:09

AlikElzin-kilaka


1 Answers

I have faced similar issues while debugging applications that uses threads. I guess your application is multi-threaded one, because I used to face things like this only at that situation. This could be because when you run the program directly mostly all your threads will be started at the same time. But while in debug mode one of your thread which has the breakpoint set will be holding, where as other threads which started along would have been completed already or the other way around. That's the reason people say debugging a multi threaded application is bit more difficult unless you maintain the priority or make threads synchronized.

Hope this info helps. So instead of stopping the flow with a break point, try to print the value where you need to know the value using sysout or things like that, which is like just running the program but still debugging, your own way:)

like image 65
Tapeshvar Avatar answered Sep 21 '22 06:09

Tapeshvar