Results 1 to 7 of 7
  1. #1
    bizso is offline Member
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default watch expression in debug mode

    Hi,
    I'm new to eclipse and trying to get hang of debugging. When I execute my code in debug mode this is what I see at local variables:

    num = 45632

    when I right click on "num" in the variables view and select inspect, I see "num" and "45632" in the expressions view. However, when I right click there and select Convert to Watch Expression I get this message:

    "Evaluations must contain either an expression or a block of well-formed statements"

    Similarly, when I highlight "num" in the editor and right click inpsect, I get the same error message. I tried to use the display view, typed in num without a semicolon, but that didn't work either. Any help?

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    At what time you check the value, before debugger comes to that line, or after the execution. May be a garbage collection it is. What exactly num holds, type? Can you show a code segment here related to this?

  3. #3
    bizso is offline Member
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    At what time you check the value, before debugger comes to that line, or after the execution. May be a garbage collection it is. What exactly num holds, type? Can you show a code segment here related to this?
    This is what's happening:

    Java Code:
    import org.junit.Test;
    
    public class AClassTest extends TestCase{
      @Test
      public void testTest(){
        AClass aClass = new AClass();
        int num = aClass.getTest();
        
      }
    }
    public class AClass {
      public int getTest() {
         return 45632;
      }
    }
    After
    Java Code:
    int num = aClass.getTest();
    has been executed. I am able to see num in the variables field, and also able to see the value when I hover above it in debug mode. But when I highlight it and click inspect, or add to watch expression, I get that strange error message.

    However, if I write

    Java Code:
    public class AClassTest extends TestCase{
      @Test
      public void testTest(){
        AClass aClass = new AClass();
        int num = 45632;
        
      }
    }
    Then everything is fine... ??

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Hmmm, interesting. I'm not an Eclipse user. However I test your code in NetBeans and I didn't get any error message as you said. There is nothing wrong in your code, seems to me that's the ways debugger deals with.

    We'll see is anyone comes with the same issue. If someone, Eclipse user, able to test this code and let us know really helpful.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Hmmm, interesting. I'm not an Eclipse user. However I test your code in NetBeans and I didn't get any error message as you said. There is nothing wrong in your code, seems to me that's the ways debugger deals with.

    We'll see is anyone comes with the same issue. If someone, Eclipse user, able to test this code and let us know really helpful.

  6. #6
    bizso is offline Member
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default

    update...

    I have tried out the same JUnit test case debugging in NetBeans 6.7 and everything works fine there (it correctly evaluates the watch expressions). So it would appear that this is an Eclipse specific problem...

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Yes, seems like that. Not NetBeans it works fine. That's why I say if another Eclipse user able to test the same code, and let us know, to narrow down the exact scenario.

Similar Threads

  1. Debug challenge: how do you debug a Java program?
    By CJSLMAN in forum New To Java
    Replies: 60
    Last Post: 07-04-2009, 10:28 AM
  2. How to enable debug mode in eclipse
    By msgbharath in forum New To Java
    Replies: 3
    Last Post: 01-10-2009, 02:20 AM
  3. Watch TV on PC - 12,000 TV Channels and Movies, save money Get $10 rebate.
    By arturmoniswork in forum Reviews / Advertising
    Replies: 0
    Last Post: 12-30-2008, 05:56 AM
  4. [SOLVED] Folder watch Issue
    By jazz2k8 in forum New To Java
    Replies: 13
    Last Post: 07-24-2008, 05:46 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •