简体   繁体   English

错误 - ''在 class 节点中找不到主方法,请将主方法定义为...”在以下代码中:

[英]Error - ''Main method not found in class Node, please define the main method as…" in the following code:

Exact error: "Error: Main method not found in class Node, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application" Exact error: "Error: Main method not found in class Node, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application"

class Node{
    int key;
    Node left, right;

    public Node(int item){
        key = item;
        left = right = null;
    }
}

class BinaryTree{
    Node root;

    BinaryTree(){
        root = null;
    }

    void printPostorder(Node node){
        if(node == null)
            return;
        
        printPostorder(node.left);
        printPostorder(node.right);
        System.out.print(node.key + " ");
    }

    void printPostorder(){ printPostorder(root);}

    public static void main(String[] args){
        BinaryTree tree = new BinaryTree();
        tree.root = new Node(1);
        tree.root.left = new Node(2);
        tree.root.right = new Node(3);

        System.out.println("\nPostorder: ");
        tree.printPostorder();
    }
}

But the main function has been defined.但是主要的function已经定义好了。

I suspect you've named the java file as "Node.java" instead of "BinaryTree.java", the code throws error since there isn't any main function in class Node (that you're trying to run) but in class BinaryTree . I suspect you've named the java file as "Node.java" instead of "BinaryTree.java", the code throws error since there isn't any main function in class Node (that you're trying to run) but in class BinaryTree The problem shall resolve if you rename your file to BinaryTree.如果您将文件重命名为 BinaryTree,问题将得到解决。

暂无
暂无

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

相关问题 错误:在 class Main 中找不到 Main 方法,请定义 main 方法 - Error: Main method not found in class Main, please define the main method 错误:在类中找不到main方法,请定义main方法 - Error:main method not found in the class, please define the main method 错误:在 class XXX 中找不到主方法,请定义主方法 - Error: main method not found in class XXX, please define the main method 错误:在类mainGUI中找不到主要方法,请将该主要方法定义为:public static void main(String [] args) - Error: Main method not found in class mainGUI, please define the main method as: public static void main(String[] args) “错误:在Grad类中找不到主要方法,请将该主要方法定义为:public static void main(String [] args)” - “Error: Main method not found in class Grad, please define the main method as: public static void main(String[] args)” 错误:在 class 中找不到主要方法,请将主要方法定义为:public static void main(String[] args) - Error: Main method not found in class, please define the main method as: public static void main(String[] args) 错误:在类Text中找不到主要方法,请将该主要方法定义为:public static void main(String [] args) - Error: Main method not found in class Text, please define the main method as: public static void main(String[] args) 错误:在Binary类中找不到主要方法,请将该主要方法定义为:public static void main(String [] args) - Error: Main method not found in class Binary, please define the main method as: public static void main(String[] args) 错误:在TextBook类中找不到主要方法,请将该主要方法定义为:public static void main(String [] args) - Error: Main method not found in class TextBook, please define the main method as: public static void main(String[] args) “错误:在 MyClass 类中找不到主方法,请将主方法定义为...” - "Error: Main method not found in class MyClass, please define the main method as..."
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM