[英]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.