![](/img/trans.png)
[英]Error: Main method not found in class Main, please define the main method
[英]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"
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();
}
}
但是主要的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
。 如果您將文件重命名為 BinaryTree,問題將得到解決。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.