eclipse 为什么我不断收到“评估必须包含一个表达式或一组格式正确的语句”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17306195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why do I keep getting "Evaluations must contain either an expression or a block of well-formed statements"?
提问by ddavison
In my code, I am trying to output the value of src
in the expressions window.
在我的代码中,我试图src
在表达式窗口中输出 的值。
public void doIt() {
String src = "test";
System.out.println(src);
}
In Eclipse. I set a breakpoint on a line 3, and I open the "Expressions" window.
在 Eclipse 中。我在第 3 行设置了一个断点,然后打开“表达式”窗口。
I add an expression src
to evaluate, and I get
我添加了一个表达式src
来评估,我得到
I've used the Expressions features... COUNTLESS times in my years of Java debugging.. Why does this happen now?
我已经使用了表达式功能......在我多年的 Java 调试中无数次......为什么现在会发生这种情况?
I've just recently started using Eclipse Juno.. vs Indigo. Did they change the way Expressions work?
我最近才开始使用 Eclipse Juno .. vs Indigo。他们是否改变了 Expressions 的工作方式?
回答by user2087898
If your code use any generics, you may want to check this bug:
如果您的代码使用任何泛型,您可能需要检查此错误:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=341232
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.
出现在 Eclipse 4.2 之前的所有版本中。简而言之,某些泛型表达式会导致 Eclipse 在任何评估中完全失败(请参见此示例:https: //bugs.eclipse.org/bugs/attachment.cgi?id=224760)。不确定您的代码是否使用任何泛型,但如果是这样,可能就是这样。请注意,在您的类中的某处拥有一种麻烦的泛型就足够了,而在您的方法中则不需要。
回答by Waqar Detho
I had the same problem and I remove a generic method in my code. It work for me.
我遇到了同样的问题,我在代码中删除了一个通用方法。它对我有用。
回答by mad_lobster
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:
我只是花了很多时间来弄清楚,如果您要创建一个包“Foo”,并且在这个包中,您将创建一个名为“Foo”的类,如下所示:
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.
这个错误可以重现到当前的 Eclipse Neon 4.7。
回答by Jolly1234
(Assuming you're compiling 1.5+ code)I had the same problem, here's what I did to fix it:
(假设您正在编译 1.5+ 代码)我遇到了同样的问题,这是我修复它的方法:
- 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
- 确保你的java编译器版本是1.5+
- 修复与该类有关的所有语法/类相关错误。我的类路径中有许多缺少的依赖项。
- 确保该特定项目的 JRE 也是 1.5+
回答by java-ocean
Check if you have updated version of Eclipse, looks like this issue is fixedin Eclipse 3.3
检查您是否有更新版本的 Eclipse,看起来这个问题已在 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.
我的 Eclipse 版本是 3.8.2,如果我在第 2 行计算表达式,那么我也会收到相同的错误,但在第 3 行它的计算正确。
回答by Noumenon
According to https://stackoverflow.com/a/21763943/733092, this happens when the class contains a generic method like
根据https://stackoverflow.com/a/21763943/733092,当类包含通用方法时会发生这种情况
public <T extends something> T myMethod() {};