简体   繁体   中英

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...

When I refresh ( F5 ) the package, these problems are sort of solved. But they happen again when I create a new class or when I restart Eclipse. So I wanted a different solution from keep pressing F5 everytime...

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. Close this window. Then, go to Window -> Show View -> Package Explorer. Then create your .java files there. The issue is that the Project Explorer window looks EXACTLY the same way as the Package Explorer.

@Rammohan's answer helped me but I can't vote it up or apparently add a comment because of low reputation. Being new to Eclipse I didn't get what he meant at first, so wanted to add a little detail for other people.

From the top menu it's Window -> Perspective -> Open Perspective -> 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). Switching to the Java perspective cleared it right up.

I also had same problem with eclipse. This issue is resolved after changing Perspective mode from "Debug" to "Java". Two same class files appear when Eclipse Perspective is in "Debug" mode. In "Java" perspective, this issue is resolved.

Hope this helps if someone facing same issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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