简体   繁体   English

如何找到“已在未命名的包中定义”的Java类?

[英]How can I find a Java class that's “already defined in an unnamed package”?

I'm trying to convert a FlowLayout() UI to a GridBagLayout() UI. 我正在尝试将FlowLayout() UI转换为GridBagLayout() UI。 After a few modification and tests, I started getting a compiler error: 经过一些修改和测试后,我开始收到编译错误:

*classname* is already defined in unnamed package

and I decided to roll back to the FlowLayout() version--my last working version. 我决定回滚到FlowLayout()版本 - 我最后一个工作版本。 That version compiles fine, but when I run (from the command line), my messed up GridBagLayout() is displayed. 那个版本编译得很好,但是当我运行时(从命令行),我的乱搞GridBagLayout()被显示出来。

I tried renaming the .java file, but I get the compiler error noted above. 我尝试重命名.java文件,但是我得到了上面提到的编译器错误。 I restarted my console window and notepad, in case something was stuck in memory somewhere. 我重新启动了我的控制台窗口和记事本,以防某些东西卡在内存中。 That did not fix the problem. 这没有解决问题。

However, I did take the FlowLayout() version to a laptop on which I hadn't compiled the GridBagLayout() changes. 但是,我确实将FlowLayout()版本带到了我没有编译GridBagLayout()更改的笔记本电脑上。 On that machine, it ran just fine, giving me the FlowLayout() I was expecting. 在那台机器上,它运行得很好,给了我期待的FlowLayout()

I've scanned my /java directory for *.class, deleted all the classes I found, but I still get the error. 我已经扫描了我的/ java目录中的* .class,删除了我找到的所有类,但我仍然得到错误。 I'm running Win7 if it makes a difference. 如果它有所作为,我正在运行Win7。 Notepad is my "IDE" and I'm running everything from the command prompt. 记事本是我的“IDE”,我在命令提示符下运行所有​​内容。

What do I need to look for to flush this "unnamed package"? 我需要寻找什么来刷新这个“未命名的包”?

All of your files without a leading package statement. 所有文件都没有前导package语句。 Anyway, as reported in Java docs : 无论如何,正如Java文档中所报告的那样:

Generally speaking, an unnamed package is only for small or temporary applications or when you are just beginning the development process. 一般来说,一个未命名的包只适用于小型或临时应用程序,或者刚刚开始开发过程。 Otherwise, classes and interfaces belong in named packages. 否则,类和接口属于命名包。

Refer to the link posted by @esseks to understand about Java packages. 请参阅@esseks发布的链接以了解Java包。 I'm posting just to help you find any duplicate class definitions fast by using findstr (Windows equivalent of grep ) 我发帖只是为了帮助您使用findstr快速找到任何重复的类定义(Windows等效于grep

C:\> CD C:\path\to\java

// delete all .class files
C:\path\to\java>del /S *.class

// find all .java files with FlowLayout class definition
C:\path\to\java>findstr /S /I /N /C:"class flowlayout" *.java

// find all .java files with GridBagLayout class definition
C:\path\to\java>findstr /S /I /N /C:"class gridbaglayout" *.java

Legend: 传说:

  • /S = Recurse sub-directories / S =递归子目录
  • /I = Case-insensitive match / I =不区分大小写的匹配
  • /N = Print line numbers / N =打印行号
  • /C = String to find in the files / C =要在文件中查找的字符串

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

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