尽管设置正确,Eclipse 仍无法识别自定义类
我的项目中有以下设置:
com.foo
- Main
com.foo.util
- StringUtil
在 Main
中,我导入 StringUtil
using
package com.foo;
import com.foo.util.StringUtil;
并像使用它一样使用它;
StringUtil string = new StringUtil();
然而,eclipse 不断告诉我 StringUtil 无法解析为类型 - 这是怎么回事?
我已经尝试刷新项目,将其重新导入为新项目,单击构建路径,但一切似乎都设置正确。
但 Eclipse 仍然无法识别该类,并且不会编译我的项目。
I have the following setup in my project:
com.foo
- Main
com.foo.util
- StringUtil
In Main
I import the StringUtil
using
package com.foo;
import com.foo.util.StringUtil;
And use it just as you would use it;
StringUtil string = new StringUtil();
Yet, eclipse keeps telling me that StringUtil cannot be resolved to a type - how can this be?
I already tried refreshing the project, reimporting it as a new project, clicked through the build paths but everything seems to be set up correctly.
But still, eclipse doesn't recognize the class and won't compile my project.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
编辑:原来的问题采用这种格式:
因此我的答案是:
因为
StringUtil
位于com.foo.util
而不是com.foo
。将其更改为
import com.foo.util.StringUtil
。EDIT: The original question had this format:
Thus my answer was:
Because
StringUtil
is incom.foo.util
and not incom.foo
.Change it to
import com.foo.util.StringUtil
.使用 CTRL + SHIFT + O 快捷键自动组织导入。这会节省您的时间。
Use CTRL + SHIFT + O shortcut to organize imports automatically. It will save your time.
可能是拼写错误,但在导入中它显示
import com.foo.StringUtil;
,但应该是import com.foo.util.StringUtil;
尝试按 Ctrl-1 (快速修复)当课堂焦点集中时。这给出了错误的建议Can be a typo, but in your import it says
import com.foo.StringUtil;
, but shoud beimport com.foo.util.StringUtil;
try press Ctrl-1 (Quick fix) when class is in focus. This gives suggestions on errors事实证明这是由于 eclipse 安装错误造成的。
擦除项目,再次签出并在重新启动的 Eclipse 中重新导入它解决了所有问题。
Turns out it was due to some messed up eclipse installation.
Wiping the project, checkout it again and reimport it in a restarted eclipse solved every issue.
如果有重写的构造函数,并且没有重写的构造函数 + 构造函数是公共的,那么您的类是否是公共的(我相信如果您可以导入它的话),并且那里有默认构造函数?
Is your class public (Which I believe it is if you can import it) with default constructor there if there are overriden constructor and otherwise no overridden constructor + constructor being public?
将项目复制到新项目可以解决此问题。
Copying the project to a new project solves this issue.