在 Eclipse 中,当所有 Java 源代码编译没有错误时,什么会导致包资源管理器“red-x”错误图标?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/225167/
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
In Eclipse, what can cause Package Explorer "red-x" error-icon when all Java sources compile without errors?
提问by Alfred B. Thordarson
I'm using Eclipse for Java development. All my sources compile fine and the resulting application compiles fine. However, I keep getting an "red-x" error notification in the Package Explorer.
我正在使用 Eclipse 进行 Java 开发。我的所有源代码都可以正常编译,并且生成的应用程序也可以正常编译。但是,我一直在包资源管理器中收到“red-x”错误通知。
All my sources in this source directory (too long for the snapshot) compile fine, none of the show the "red-x" error icon.
我在这个源目录中的所有源(对于快照来说太长)都编译得很好,没有一个显示“red-x”错误图标。
Any suggestions on how to fix the problem would be highly appreciated.
任何有关如何解决问题的建议将不胜感激。
采纳答案by Jan Gressmann
yeah, this happens sometimes for no apparent reason. You can go to the "Problems"-Tab (right next to console output) and see the error message, so maybe you can narrow it down that way.
是的,这种情况有时会发生,没有明显的原因。您可以转到“问题”-选项卡(在控制台输出旁边)并查看错误消息,因此也许您可以通过这种方式缩小范围。
回答by mdec
Try doing a rebuild. I've found that the red x's don't always disappear until a rebuild is done.
尝试进行重建。我发现在重建完成之前,红色的 x 并不总是消失。
回答by JeeBee
Sometimes there are build path errors in .project, and you need to switch to Resource view to actually see the file that is causing the error.
有时 .project 中存在构建路径错误,您需要切换到 Resource 视图才能实际查看导致错误的文件。
回答by Henry B
I've run into a similar problem many a time, what happens usually for me is that a java file will say it won't compile in the text editor but in the package explorer it will say it's compiling fine.
我已经多次遇到类似的问题,通常对我来说是一个 java 文件会说它不会在文本编辑器中编译,但在包资源管理器中它会说它编译正常。
Sometimes doing a 'rebuild' or 'clean-build' doesn't work, the files don't actually get built (one has to presume that eclipse thinks the files it has are up to date) and when this happens I usually open up the java build path and just move one of my dependencies down/up the pecking order. This forces eclipse to do a rebuild of everything and it always seems to work.
有时进行“重建”或“清理构建”不起作用,文件实际上并没有被构建(必须假设 eclipse 认为它拥有的文件是最新的),当发生这种情况时,我通常会打开java 构建路径,只需将我的依赖项之一向下/向上移动到啄食顺序。这迫使 eclipse 对所有内容进行重建,而且它似乎总是有效。
If you're still having problems try copying the project and seeing if you get the same behaviour and at a last ditch attempt post a bug for eclipse, it may take a while for them to fix but at least you know that you're being heard.
如果您仍然遇到问题,请尝试复制项目并查看您是否得到相同的行为,并在最后一次尝试为 Eclipse 发布错误,他们可能需要一段时间才能修复,但至少您知道您正在听到。
回答by flash
Try to clean the project and rebuild it.
尝试清理项目并重建它。
回答by VonC
To add to the previous answer, an extreme way of "cleaning" your project is to delete it (that is deleting its reference from the workspace, not deleting the actual files), and then re-import it.
Sometimes, it helps...
要补充上一个答案,“清理”项目的一种极端方法是将其删除(即从工作区中删除其引用,而不是删除实际文件),然后重新导入它。
有时,它有助于...
回答by Alfred B. Thordarson
I want to start by thanking everyone that answered. But cleaning and rebuilding was not enough in my case because the problem was still there and needed fixing.
我想首先感谢所有回答的人。但是在我的情况下,清洁和重建还不够,因为问题仍然存在并且需要修复。
Turned out that one of my package directories had accidentally been copied so that an extra directory now existed called "Copy of dagskra" containing Java files with wrong package declarations. In addition the errors in this "new" directory don't show up with a "red-x" in the package that it exists in:
结果是我的一个包目录被意外复制,因此现在存在一个名为“dagskra 副本”的额外目录,其中包含带有错误包声明的 Java 文件。此外,这个“新”目录中的错误不会在它所在的包中显示为“red-x”:
来自 Package Explorer 的快照显示了错误的“dagskra 副本”目录 http://www.freeimagehosting.net/uploads/a824304b18.png
It was the hint of reading the "Problems" tab :-) that turned me into the right direction, so I'm selecting that answer as the accepted answer because this is what I needed:
正是阅读“问题”选项卡 :-) 的提示使我转向了正确的方向,因此我选择该答案作为已接受的答案,因为这正是我所需要的:
Snapshot from Problems tab http://www.freeimagehosting.net/uploads/dea26d5dd0.png
问题选项卡的快照 http://www.freeimagehosting.net/uploads/dea26d5dd0.png
Hoping this will help others...
希望这会帮助其他人......
回答by madlep
As others have said, bad file references in the build path is often the culprit.
正如其他人所说,构建路径中的错误文件引用通常是罪魁祸首。
Usually a .jar file that has been moved/deleted. Eclipse expects to find everything referenced on the build path at the location specified, and will complain if not.
通常是已移动/删除的 .jar 文件。Eclipse 期望在指定位置找到构建路径上引用的所有内容,否则会报错。
回答by Rahul
FindBugs also puts a red-x against files/packages to indicate static code analysis errors.
FindBugs 还针对文件/包放置了一个 red-x 以指示静态代码分析错误。
回答by Rahul
I have run through this. My case was more involved. The project was packaged fine from maven command line.
我已经通过了这个。我的案子涉及更多。该项目从 maven 命令行打包得很好。
Couple of things I made. 1. One class has many imports that confused eclipse. Cleaning them fixed part of the problem 2. One case was about a Setter, pressing F3 navigating to that Setter although eclipse complained it is not there. So I simply retyped it and it worked fine (even for all other Setters)
我做的几件事。1.一个类有很多混淆eclipse的imports。清理它们修复了部分问题 2. 一个案例是关于一个 Setter,按 F3 导航到那个 Setter 尽管 eclipse 抱怨它不存在。所以我只是重新输入它并且它工作正常(即使对于所有其他 Setter)
I am still struggling with Implicit super constructor Item() is undefined for default constructor. Must define an explicit constructor"
我仍在努力解决隐式超级构造函数 Item() 对于默认构造函数未定义。必须定义一个显式构造函数”