Java帮助: why can't I access the static methods declared in a class outside the current main method file

标签 java sax

遵循 SAX 的 JavaDocs 教程: 主方法无法识别方法usage()。据我所知,它应该是可访问的,因为这些方法被声明为静态,并且与主方法存在于同一包中。

public class Main {
    public static void main(String args[]){
        String filename = null;

//Checks to see if commnad line arguments are present
        for (int i = 0; i < args.length; i++) {
            filename = args[i];
            if (i != args.length - 1) {
                usage();
            }
        }

        if (filename == null) {
            usage();
        } 

//Defined in the same package as the main method
    public class SAXLocalNameCount extends DefaultHandler{
        private Hashtable tags;

        public void startDocument() throws SAXException{
            tags = new Hashtable();
        }

//The problem method    
    private static void usage() {
       System.err.println("Usage: SAXLocalNameCount <file.xml>");
       System.err.println("       -usage or -help = this message");
       System.exit(1);
    }
}

最佳答案

usage() 似乎是 SAXLocalNameCount 类的成员,而不是 Main 类的成员。尽管有缩进。

关于Java帮助: why can't I access the static methods declared in a class outside the current main method file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28399639/

相关文章:

java - SAX 解析器不工作

java - SAX 解析器;读取特殊字符时出现错误

java - Component.CENTER 不适用于 Tablelayout(特别是使用 CODENAMEONE)

java - 欧拉甚至斐波那契计划

java - 如何使用 JTextArea 将新选项卡添加到 JTabbedPane

java - Cassandra 保存键空间时出错并且不在 opscenter 中显示键空间

java - 使用 sax 解析器和 imageloader 类将图像解析为 listview

java - 不构建 DOM 的 XML 转换

python 萨克斯错误 "junk after document element"

java - 存储、转换为视频流 Android 屏幕