简体   繁体   English

Eclipse 正在创建两个类文件

[英]Eclipse is creating two class files

When I create a new class inside a package for some reason it creates two class files: one inside of the package and one out of it.当我出于某种原因在包内创建一个新类时,它会创建两个类文件:一个在包内,一个在包外。 I wanted to know why this is happening?我想知道为什么会这样? Also, at times, Eclipse are kind of "hiding" some of my classes, so that they do not appear in the project explorer, although when you create a new class file with the same name of the class that disappeared, it says the class already exists...此外,有时,Eclipse 有点“隐藏”我的一些类,因此它们不会出现在项目资源管理器中,尽管当您创建一个与消失的类同名的新类文件时,它会显示类已经存在...

When I refresh ( F5 ) the package, these problems are sort of solved.当我刷新( F5 )包时,这些问题就解决了。 But they happen again when I create a new class or when I restart Eclipse.但是当我创建一个新类或重新启动 Eclipse 时,它​​们会再次发生。 So I wanted a different solution from keep pressing F5 everytime...所以我想要一个不同的解决方案,而不是每次都按F5 ......

So I had this same problem and it may be for the same reason.所以我遇到了同样的问题,可能是出于同样的原因。 The problem can be because you are creating the .java files in the Project Explorer window.问题可能是因为您正在项目资源管理器窗口中创建 .java 文件。 Close this window.关闭此窗口。 Then, go to Window -> Show View -> Package Explorer.然后,转到窗口 -> 显示视图 -> 包资源管理器。 Then create your .java files there.然后在那里创建您的 .java 文件。 The issue is that the Project Explorer window looks EXACTLY the same way as the Package Explorer.问题是,项目浏览器窗口看上去完全的方式在Package Explorer相同。

@Rammohan's answer helped me but I can't vote it up or apparently add a comment because of low reputation. @Rammohan 的回答对我有所帮助,但由于声誉低,我无法投票或显然无法添加评论。 Being new to Eclipse I didn't get what he meant at first, so wanted to add a little detail for other people.作为 Eclipse 的新手,我一开始没明白他的意思,所以想为其他人添加一些细节。

From the top menu it's Window -> Perspective -> Open Perspective -> Java.从顶部菜单它是窗口 -> 透视图 -> 打开透视图 -> Java。

I had unwittingly switched to the Debug perspective and had the double-creation problem happening in src/test/java (but not in src/main/java, still don't get why).我无意中切换到 Debug 透视图,并且在 src/test/java 中发生了双重创建问题(但不在 src/main/java 中,仍然不明白为什么)。 Switching to the Java perspective cleared it right up.切换到 Java 透视图就清楚了。

I also had same problem with eclipse.我也遇到了同样的 eclipse 问题。 This issue is resolved after changing Perspective mode from "Debug" to "Java".将透视模式从“调试”更改为“Java”后,此问题已解决。 Two same class files appear when Eclipse Perspective is in "Debug" mode.当 Eclipse Perspective 处于“调试”模式时,会出现两个相同的类文件。 In "Java" perspective, this issue is resolved.从“Java”的角度来看,这个问题已经解决。

Hope this helps if someone facing same issue.如果有人面临同样的问题,希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM