eclipse 线程“main”中的异常:java.lang.error
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1897123/
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
Exception in thread "main" : java.lang.error
提问by Amokrane Chentir
I've just created a project on Eclipse and imported some source files (existing project). But I can't compile it ! Ok, the project has got several source files, so I wanted to compile only the Main.java file (with eclipse not in the command line, in the command line it worked!) but all what I get is this error :
我刚刚在 Eclipse 上创建了一个项目并导入了一些源文件(现有项目)。但我无法编译它!好的,该项目有几个源文件,所以我只想编译 Main.java 文件(Eclipse 不在命令行中,在命令行中它可以工作!)但我得到的只是这个错误:
http://www.screencast.com/users/Amokrane/folders/Jing/media/82d772dd-10cd-4552-b1d0-3cf18bf39f13
http://www.screencast.com/users/Amokrane/folders/Jing/media/82d772dd-10cd-4552-b1d0-3cf18bf39f13
As you can see the Main.java file is straighforward, just a hello world !
正如您所看到的 Main.java 文件很简单,只是一个 hello world !
What's the matter ?
怎么了 ?
Thanks
谢谢
回答by Jon Skeet
"Unresolved compilation problem" means that the class hasn't compiled successfully. Eclipse will still let you run code that doesn't compile, but any of the specific bits which don't compile will throw this error. Look in the "Problems" tab to see what's wrong.
“未解决的编译问题”意味着该类尚未成功编译。Eclipse 仍会让您运行无法编译的代码,但任何无法编译的特定位都会引发此错误。查看“问题”选项卡,看看有什么问题。
From the look of the Package Explorer view, every single class has a problem... perhaps the file location doesn't match the package declaration? That would match the position of the pink box just to the right of the vertical scrollbar for the class - it suggests that the error is right at the top of the file, which is where the package declaration would be.
从包资源管理器视图的外观来看,每个类都有问题......也许文件位置与包声明不匹配?这将匹配类的垂直滚动条右侧的粉红色框的位置 - 它表明错误就在文件的顶部,这是包声明的位置。
回答by Michael Borgwardt
You have a compilation error at the top of your Main.java
file, just out of sight in the screenshot. Probably an unresolvable import or a wrong/missing package declaration.
您的Main.java
文件顶部有一个编译错误,在屏幕截图中看不到。可能是无法解析的导入或错误/丢失的包声明。
回答by Vijayakanth G
It is simple in my case that the imported project needs 32 bit jre to run but cannot be compiled in the same. In IDE, if you click run, it will try to compile and run the project in single shot so fails due to 32 bit jre for compilation with the above reported error. So i used 64 bit compiler and started to run and got compiled successfully but thrown error that needs 34 bit jre for some of the SWT used in the project. Again i changed the 32 bit jre and run the project, it is gone ! THE ERROR IS GONE NOW !
在我的情况下很简单,导入的项目需要 32 位 jre 才能运行,但不能以相同的方式编译。在IDE中,如果你点击运行,它会尝试单次编译和运行项目,因此由于32位jre编译失败,并报上述错误。所以我使用了 64 位编译器并开始运行并成功编译但抛出错误,该错误需要 34 位 jre 用于项目中使用的某些 SWT。我再次更改了 32 位 jre 并运行该项目,它不见了!错误消失了!
回答by Tom Stickel
You can get the error "Exception in thread "main" java.lang.Error: Unresolved compilation problem:" if your public class name differs from your file name.
如果您的公共类名与您的文件名不同,您可能会收到错误“线程“main”java.lang.Error:未解决的编译问题中的异常:”。
example:
例子:
File Name:
文档名称:
ServiceRequest.java
Inside file, class is named differently; like
在文件内部,类的命名不同;喜欢
public class Service