Why do I keep getting “Evaluations must contain either an expression or a block of well-formed statements”?

后端 未结 6 1512

In my code, I am trying to output the value of src in the expressions window.

public void doIt() {
    String src = \"test\";
    System.out.pri         


        
相关标签:
6条回答
  • 2021-01-17 11:22

    If your code use any generics, you may want to check this bug:

    https://bugs.eclipse.org/bugs/show_bug.cgi?id=341232

    Occurs in all version of Eclipse up to 4.2. In short certain generics expressions cause Eclipse to completely fail on any evaluation (please see this example: https://bugs.eclipse.org/bugs/attachment.cgi?id=224760). Not sure whether your code uses any generics, but if so, this may be it. Note that it is enough to have one of the troublesome generics somewhere in your class, not necessary in your method.

    0 讨论(0)
  • 2021-01-17 11:24

    According to https://stackoverflow.com/a/21763943/733092, this happens when the class contains a generic method like

    public <T extends something> T myMethod() {};
    
    0 讨论(0)
  • 2021-01-17 11:29

    Check if you have updated version of Eclipse, looks like this issue is fixed in Eclipse 3.3

    My Eclipse Version is 3.8.2 and if I evaluate the expression on line 2 then I am also receiving the same error but at line 3 its evaluating properly.

    0 讨论(0)
  • 2021-01-17 11:32

    I had the same problem and I remove a generic method in my code. It work for me.

    0 讨论(0)
  • 2021-01-17 11:40

    I just spent TONS of time to figure out that if you will create a package "Foo" and inside this package you'll create class called "Foo", like this:

    package Foo;
    
    public class Foo{
        public Foo () {};
    }
    

    After the point when you use this class first time in your program, you will not be able to use expressions anymore:

    import Foo.Foo; //this is the devil i think
    
    public static void main(String[] args){
        EventQueue.invokeLater(new Runnable(){
            public void run(){
                //debug expressions works fine
                Foo tmp = new Foo();
                //debug expressions wouldn't work anymore
            }
        });
    }
    

    This bug can be reprodused up to current Eclipse Neon 4.7.

    0 讨论(0)
  • 2021-01-17 11:40

    (Assuming you're compiling 1.5+ code)I had the same problem, here's what I did to fix it:

    • Ensure that your java compiler version is 1.5+
    • Fix all syntax/class related errors pertaining to that class. I had a number of missing dependencies in my classpath.
    • make sure the JRE is also 1.5+ for that specific project
    0 讨论(0)
提交回复
热议问题