尽管设置正确,Eclipse 仍无法识别自定义类

发布于 2024-12-28 10:44:13 字数 451 浏览 0 评论 0原文

我的项目中有以下设置:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

习惯成性 2025-01-04 10:44:13

编辑:原来的问题采用这种格式:

package com.foo;
import com.foo.StringUtil;

因此我的答案是:

因为 StringUtil 位于 com.foo.util 而不是 com.foo

将其更改为import com.foo.util.StringUtil

EDIT: The original question had this format:

package com.foo;
import com.foo.StringUtil;

Thus my answer was:

Because StringUtil is in com.foo.util and not in com.foo.

Change it to import com.foo.util.StringUtil.

狼性发作 2025-01-04 10:44:13

使用 CTRL + SHIFT + O 快捷键自动组织导入。这会节省您的时间。

Use CTRL + SHIFT + O shortcut to organize imports automatically. It will save your time.

℡寂寞咖啡 2025-01-04 10:44:13

可能是拼写错误,但在导入中它显示 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 be import com.foo.util.StringUtil; try press Ctrl-1 (Quick fix) when class is in focus. This gives suggestions on errors

独﹏钓一江月 2025-01-04 10:44:13

事实证明这是由于 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.

画中仙 2025-01-04 10:44:13

如果有重写的构造函数,并且没有重写的构造函数 + 构造函数是公共的,那么您的类是否是公共的(我相信如果您可以导入它的话),并且那里有默认构造函数?

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?

小嗲 2025-01-04 10:44:13

将项目复制到新项目可以解决此问题。

Copying the project to a new project solves this issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文