eclipse 包与java代码中的类型发生冲突
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7089806/
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
The package collides with a type in java code
提问by solar
I have a question about eclipse version 3.6.1.
I had run my code well before, but now I open the eclipse and my code appear red line at the package.
The error message is The package com.test collides with a type.
How should I solve this problem?
My code is as the following:
我有一个关于 Eclipse 3.6.1 版的问题。
我以前运行过我的代码,但现在我打开 eclipse,我的代码在包中出现红线。
错误消息是The package com.test collides with a type。
我应该如何解决这个问题?
我的代码如下:
package com.test;
public class test extends Activity{
.....
.....
}
包 com.test;
公共类测试扩展 Activity{
.....
.....
}
Thank you for your help~:)
谢谢你的帮助~:)
回答by Stephen C
I've changed the class name and the file name to Test, but it always wrong at the package com.test;, I have no idea about that problem.
我已经把类名和文件名改成了Test,但是com.test这个包总是出错,我不知道这个问题。
At this point, Eclipse could just be confused.
在这一点上,Eclipse 可能会感到困惑。
Do a "project > clean" on all projects in your workspace. If that fails try the various other tricks that are typically used to de-confuse Eclipse.
对工作区中的所有项目执行“项目 > 清理”。如果失败,请尝试通常用于消除 Eclipse 混淆的各种其他技巧。
回答by Narbhakshi
Even after i corrected the naming conflicts and changed the package declaration to match its location, Eclipse showed this error message.
即使在我纠正了命名冲突并更改了包声明以匹配其位置之后,Eclipse 仍显示此错误消息。
I deleted my project from the Eclipse package explorer(not from the computer) and then imported the same project after restarting the Eclipse. Problem solved!
我从 Eclipse 包资源管理器(不是从计算机)中删除了我的项目,然后在重新启动 Eclipse 后导入了相同的项目。问题解决了!
回答by Anthony Grist
The easiest solution is to follow the Java naming convention whereby class names start with an uppercase letter; so Test rather than test.
最简单的解决方案是遵循 Java 命名约定,即类名以大写字母开头;所以测试而不是测试。