简体   繁体   English

线程“ main”中的异常java.lang.NoSuchMethodError:main-如何解决?

[英]Exception in thread “main” java.lang.NoSuchMethodError: main - how to fix it?

Please help me to fix my simple program. 请帮助我修复我的简单程序。 I'm just newbie of Java Programming. 我只是Java编程的新手。 When i write the program, and the program has been success compile but can't run cause the massage error "Exception in thread "main" java.lang.NoSuchMethodError: main" has been show. 当我编写程序时,程序已成功编译但无法运行,导致显示错误消息“线程“ main”中的异常” java.lang.NoSuchMethodError:main。 Everybody can help me to run this program ? 每个人都可以帮助我运行该程序吗?

The coding is: 编码为:

Person class... 人类...

//Program to display student details using inheritance
class Person {
    String name;
    int age;
}

Student class... 学生班...

class Student extends Person
{
    int mark1,mark2,mark3;
    void putdata()
    {
        System.out.println("Name = " + name);
        System.out.println("Age = " + age);
        System.out.println("Mark1 = " + mark1);
        System.out.println("Mark2 = " + mark2);
        System.out.println("Mark3 = " + mark3);
    }
 }

Marks class... 商标课...

class Marks
{
    public static void main(String[] args)
    {
        Student obj1=new Student();
        obj1.name="Sultanah";
        obj1.age=17;
        obj1.mark1=67;
        obj1.mark2=87;
        obj1.mark3=97;
        obj1.putdata();
    }
}

JVM when try to launch the program looks for the class with the same name as the name passed to run the program. JVM在尝试启动程序时会查找与传递给运行程序的名称相同名称的类。 Once the class is found then it looks for the main method in it. 找到该类后,它将在其中查找main方法。 So make sure that you are running the program using Mark as the class name because that is the class that contains your main method. 因此,请确保您正在使用Mark作为类名来运行程序,因为那是包含您的main方法的类。

Either: 要么:

  1. Your main() method shoudl be placed in the Student class, if that's the class you're executing, or 如果要执行的类是您的main()方法,则应将其放置在Student类中, 或者

  2. You should be executing the class that does contain the main() method, ie Marks . 您应该执行包含main()方法的类,即Marks

It seems you trying to run class that doesn't have main method. 看来您尝试运行没有主要方法的类。 according to your code Marks.java has main method so after compilation you can run Marks class using 根据您的代码Marks.java具有main方法,因此在编译后,您可以使用

java Marks

暂无
暂无

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

相关问题 如何解决此错误? 线程“ main”中的异常java.lang.NoSuchMethodError:main - How do I fix this error? Exception in thread “main” java.lang.NoSuchMethodError: main “线程“ main”中的异常java.lang.NoSuchMethodError” - “Exception in thread ”main“ java.lang.NoSuchMethodError ” 如何在线程“main”中修复此异常 java.lang.NoSuchMethodError: org.apache.poi.POIXMLDocumentPart.getPackageRelationship - How to fix this Exception in thread “main” java.lang.NoSuchMethodError: org.apache.poi.POIXMLDocumentPart.getPackageRelationship Java错误:线程“main”中的异常java.lang.NoSuchMethodError:main - Java error: Exception in thread “main” java.lang.NoSuchMethodError: main 不断在线程“ main”中获取异常java.lang.NoSuchMethodError:main? - keep getting Exception in thread “main” java.lang.NoSuchMethodError: main? 线程“main”中的异常 java.lang.NoSuchMethodError: main - Exception in thread "main" java.lang.NoSuchMethodError: main 为什么线程“ main”中的异常java.lang.NoSuchMethodError:main? - Why Exception in thread “main” java.lang.NoSuchMethodError: main? 线程“ main”中的异常java.lang.NoSuchMethodError:main //有什么问题? - Exception in thread “main” java.lang.NoSuchMethodError: main // What is wrong? Java安装不正确吗? 线程“ main”中的异常java.lang.NoSuchMethodError - Is Java not installed correctly? Exception in thread “main” java.lang.NoSuchMethodError 线程“ main”中的Javap异常java.lang.NoSuchMethodError - Javap Exception in thread “main” java.lang.NoSuchMethodError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM