java - 重复的类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19318704/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 16:03:10  来源:igfitidea点击:

java - duplicate class

javaclassnetbeans

提问by Robbo_UK

Confused as to why I get duplicate class error for the following code?

对为什么我收到以下代码的重复类错误感到困惑?

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package database_console;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


/**
 *
 * @author davidsonr
 */
public class DBConnect {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
    }
}

Netbeans highlights DBConnect as red with duplicate class error.

Netbeans 将 DBConnect 突出显示为红色,并出现重复的类错误。

采纳答案by Eduardo Dennis

This is a known issue with netbeans BUG 226360

这是 netbeans BUG 226360 的一个已知问题



it might help to clear Netbeans cache:



清除 Netbeans 缓存可能会有所帮助:

Go to Help-> Aboutand you will see

转到Help->About你会看到

Cache directory:Path\to\Directory

缓存目录:Path\to\Directory

Close NetBeans, go to specified directory and delete everything.

关闭 NetBeans,转到指定目录并删除所有内容。

回答by SpringLearner

this might be due to 2 classes with the same name in the same package

这可能是由于同一个包中有 2 个同名的类

回答by james.garriss

If the file name doesn't match the class name, NetBeans 8.0.1 will report this as a duplicate class.

如果文件名与类名不匹配,NetBeans 8.0.1 会将其报告为重复类。

回答by Christopher Hoffman

This also happens if your referencing the erroring class in a separate file in the same package, with the erroring class with an unmatching package path to the file where you are referencing erroring class.

如果您在同一个包中的单独文件中引用错误类,并且错误类与引用错误类的文件的包路径不匹配,也会发生这种情况。

For example file 1 some.incorrect.path.package

例如文件 1 some.incorrect.path.package

class_that_is_erroring{ }

class_that_is_erroring{ }

file 2 some.correct.path.package

文件 2 some.correct.path.package

class new_class{

类 new_class{

class_that_is_erroring myclass = null;

class_that_is_erroring myclass = null;

}

}

The package paths in both files must match each other and match the file system directory.

两个文件中的包路径必须相互匹配并匹配文件系统目录。