简体   繁体   English

错误:在 class Main 中找不到 Main 方法,请定义 main 方法

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

相关问题 错误:在类中找不到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) 运行Scala程序报错:Main method not found in class main,请定义main方法 - Error in running Scala Program: Main method not found in class main, please define the main method “错误:在 MyClass 类中找不到主方法,请将主方法定义为...” - "Error: Main method not found in class MyClass, please define the main method as..."
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM