[英]Error: Main method not found in class Main, please define the main method
I need help with the main method, I'm getting this error: while compiling the Project:我需要有关主要方法的帮助,我收到此错误:编译项目时:
Error: Main method not found in class Main, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
Also tried online Java compilers but no luck.还尝试了在线 Java 编译器,但没有运气。
public class Main{
String yourname = "Ayush Sahu";
int mnumber = 25;
public void justtest(){
System.out.println("This is a test Method!!!");
}
}
class testing extends Main{
String fname = "Balamukunda";
String lname = "Sahu";
int age = 25;
public void testing(){
System.out.println("This is a test Method!!!");
}
public static void main(String[] args){
//Accessing the Data of Class: Main
testing myObj1 = new testing();
System.out.println(myObj1.yourname);
System.out.println(myObj1.mnumber);
myObj1.justtest();
//Accessing the Data of Class: testing
myObj1.testing();
System.out.println(myObj1.fname);
System.out.println(myObj1.lname);
System.out.println(myObj1.age);
}
}
If you want to run in IDE, right click in middle of testing class and find Run -> Run Application it the dropdown menu and click it.如果要在 IDE 中运行,请在测试 class 中间右键单击并在下拉菜单中找到运行 -> 运行应用程序并单击它。 Try to separate each class in individual files.
尝试在单独的文件中分隔每个 class。 So you must have at least two files: Main.java and testing.java .
所以你必须至少有两个文件: Main.java和testing.java 。 I strongly recommend you to use Camel Case for class names and respect coding standard (which mean change testing to Testing or even better to Test ).
我强烈建议您将 Camel Case 用于 class 名称并尊重编码标准(这意味着将testing更改为Testing甚至更好地更改为Test )。
If not, You must change it in Manifest file or find run configuration in your IDE.如果没有,您必须在 Manifest 文件中更改它或在 IDE 中找到运行配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.