为什么我继续获取线程"main"中的"exception"? java.lang.nosuchmethoderror:main“错误? [英] Why do I keep on getting the "exception in thread "main" java.lang.nosuchmethoderror: main" error?

查看:157
本文介绍了为什么我继续获取线程"main"中的"exception"? java.lang.nosuchmethoderror:main“错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用外部方法编写了代码.

代码成功编译.
一旦运行该应用程序,它会提示我以下内容:
线程主"中的异常" java.lang.NoSuchMethodError:主"

我看不到我在做什么错.

我尝试过的事情:

I have written a code using External Methods.

The code compiles successfully.
Once I run the Application it prompts me the following:
"Exception in thread "main" java.lang.NoSuchMethodError: main"

I can''t see what I''m doing wrong.

What I have tried:

import java.io.*;

public class Employee
{
	String FirstName;
	String LastName;
	String Position;
	float Rate;
	float Hours;

	public Employee(String f, String l, String p, float r, float h)
    {
        FirstName = f;
        LastName = l;
        Position = p;
        Rate = r;
        Hours = h;
    }
    public Employee(String f,String l, String p)
    {
		LastName = l;
        FirstName = f;
        Position = p;
    }
    public String getFirstName()
    {
        return FirstName;
    }
    public String getLastName()
    {
        return LastName;
    }
    public String getPosition()
    {
        return Position;
    }
    public float getRate()
    {
        return Rate;
    }
    public float getHours()
    {
        return Hours;
    }
}

推荐答案

我不确定我已经使用外部方法编写了代码"的意思.

但是,您会收到此消息,因为您的类中没有main方法,因此它无法单独运行.您需要添加一个main方法(请参见下文),以及剩下的代码来驱动此类并实际执行某些操作.
I am not sure what you mean by "I have written a code using External Methods."

However, you get that message because there is no main method in your class, so it cannot run on its own. You need to add a main method (see below), and also the remaining code to drive this class and actually do something.
// add this inside the Employee class
    public static void main(String[] args) {
        // Add code here to create objects and interface with the user.
    }


这篇关于为什么我继续获取线程"main"中的"exception"? java.lang.nosuchmethoderror:main“错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆