git 为什么eclipse不能在同一个包中解析类?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11568855/
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
Why can't eclipse resolve class in same package?
提问by Cedric Reichenbach
I hit F5 ~1000 times and restarted eclipse (also with -clean), deleted /bin, but nothing helps. Manually importing DoodleClient does not help. DoodleClient exists and is perfectly fine, everything worked before. Clicking on "Import 'DoodleClient' ..." does nothing.
我按 F5 ~1000 次并重新启动 eclipse(也使用 -clean),删除 /bin,但没有任何帮助。手动导入 DoodleClient 没有帮助。DoodleClient 存在并且非常好,之前一切正常。单击“导入'DoodleClient'...”什么也不做。
What I did before this problem occured:
在出现这个问题之前我做了什么:
- I added *.class to .gitignore
git rm *.class
- On the next pull, hunderts of .class files were deleted by git
- 我将 *.class 添加到 .gitignore
git rm *.class
- 在下一次拉取时,git 删除了大量 .class 文件
采纳答案by Cedric Reichenbach
I could resolve it: On another project (from the same git repo), I had the same issue on several files in different packages. All I had to do was writing a white-space into the file, remove it again and save, so eclipse would re-compile it (I guess).
我可以解决它:在另一个项目(来自同一个 git repo)中,我在不同包中的几个文件上遇到了同样的问题。我所要做的就是在文件中写入一个空格,再次删除它并保存,这样 eclipse 就会重新编译它(我猜)。
Some kind of a strange behaviour... :S
某种奇怪的行为......:S
回答by samorai
Alternatively, you can highlight the project :
或者,您可以突出显示项目:
Choose Clean ...
from Project menuand if you have activated the Build Automatically
option (in the same menu), the classes will be generated anew.
Clean ...
从项目菜单中选择,如果您已激活该Build Automatically
选项(在同一菜单中),将重新生成类。
回答by Dakshila Kamalsooriya
I got the same error in Maven project. Running Maven Clean and closing the project and reopening didn't work for me. Right click project -> Maven -> Update Project worked for me.
我在 Maven 项目中遇到了同样的错误。运行 Maven Clean 并关闭项目并重新打开对我不起作用。右键单击项目 -> Maven -> 更新项目对我有用。
回答by ScottyG
I tried to refresh the workspace (F5) and clean the project, but that did not do the trick. What worked for me was to right-click on the project and select 'Close Project'.
我尝试刷新工作区 (F5) 并清理项目,但这并没有奏效。对我有用的是右键单击项目并选择“关闭项目”。
Once closed I re-opened the project. This seemed to refresh all the files for the project in Eclipse.
关闭后,我重新打开了该项目。这似乎刷新了 Eclipse 中项目的所有文件。
回答by Isaac Riley
Luckily I didn't have 1000's of errors; for my 20+ class resolution problems, what I did was to:
幸运的是,我没有出现 1000 个错误;对于我的 20 多个类解析问题,我所做的是:
- Delete a part of the name of the offending class
- Place cursor at the end (of remaining fragment of class' name), do an auto-suggest (Ctrl+space) and choose the correct class from the suggestions
- Save
- 删除违规班级名称的一部分
- 将光标放在(班级名称的剩余片段)的末尾,进行自动建议(Ctrl+空格)并从建议中选择正确的班级
- 节省
Tedious but it worked....
乏味,但它的工作......
回答by Meena
Right click on projectthen R-click on Maventhen Update Project
右键单击项目,然后右键单击Maven,然后单击更新项目
回答by thonnor
I have 3 projects in my project explorer and they have dependencies on each other.
我的项目资源管理器中有 3 个项目,它们相互依赖。
They all went nuts and I had 9000+ errors across all 3 projects.
他们都疯了,我在所有 3 个项目中都有 9000 多个错误。
It turned out that cleaning each of them in the correct order (middle, top, bottom) resolved everything.
事实证明,按照正确的顺序(中间、顶部、底部)清洁它们可以解决所有问题。
Cleaning in the correct order is what fixed my issue.
以正确的顺序清洁是解决我的问题的原因。
Just thought it was worth mentioning :)
只是觉得值得一提:)
回答by Snake Sanders
The first thing I would do is create a new class in the same package and check if it is visible from this class where you have the issue.
我要做的第一件事是在同一个包中创建一个新类,并检查它是否在您遇到问题的这个类中可见。
Also I'm not sure but you could check to change the name of your class "D" for something different.
此外,我不确定,但您可以检查更改班级“D”的名称以获得不同的名称。
and ...Check if the file actually does exist
和 ...检查文件是否确实存在
回答by egelev
I had the same problem. I tried to add the statement with the static method call again and delete the old one. Eclipse even helped me with auto-completion and after that it underlined the statement again. In my case closing the project and importing it again after that worked.
我有同样的问题。我尝试再次添加带有静态方法调用的语句并删除旧的。Eclipse 甚至帮助我自动完成,然后它再次强调了该语句。在我的情况下,关闭项目并在工作后再次导入它。
回答by Laszlo Lugosi
I have the same issue every day, and the solution is different every time. :) You can try something like these:
我每天都遇到同样的问题,每次解决的方法都不一样。:) 您可以尝试以下操作:
- Project menu - Clean
- Project - Maven - Update project (Alt+F5)
- Project - Refresh
- Project - Run as - Maven clean
- Project - Run as - Maven install
- Restart Eclipse
- Remove application from servlet container (if it is web app)
- Pray.. :)
- 项目菜单 - 清洁
- 项目 - Maven - 更新项目 (Alt+F5)
- 项目 - 刷新
- 项目 - 运行方式 - Maven clean
- 项目 - 运行方式 - Maven 安装
- 重启 Eclipse
- 从 servlet 容器中删除应用程序(如果是 Web 应用程序)
- 祈祷.. :)