静态错误:此类没有接受String []的静态void main方法。

时间:2015-09-30 19:34:30

标签: java string class static

我的代码编译得很好但是当我去运行它时,它给了我错误:

`Static Error: This class does not have a static void main method accepting String[]`

这是我的代码:

class Employee{
  private String name; //name reference field
  private int idNumber; //integer variable holding employee's ID number
  private String department; //holds the name of the employees department
  private String position; //holds the name of the employee's position in the department
  //the following is the first required constructor
  //using the terms n,i,d, and p to assign values to the above fields
  public Employee(String n, int i, String d, String p){
    name=n;
    idNumber=i;
    department=d;
    position=p;
  }
  //the following is a constructor that sets the fields blank to be filled in
  public Employee(){
    name="";
    idNumber=0;
    department="";
    position="";
  }
  //writing appropriate accessor and mutator methods for all the fields
  public void setName(String n){ name=n; }
  public void setIdNumber(int i){ idNumber = i; }
  public void setDepartment(String d){ department = d; }
  public void setPosition(String p){ position = p; }
  public String getName(){ return name; }
  public int getIdNumber(){ return idNumber; }
  public String getDepartment(){ return department; }
  public String getPosition(){ return position; }
}
//new program creating employee objects
public class EmployeeInfo 
{
  public static void main(String[] args)
  {
    //create an Employee object
    Employee employee1 = new Employee("Susan Meyers", 47899, "Accounting", "Vice President");
    //test the accessor methods
    System.out.println("***employee1***");
    System.out.println("Name: " + employee1.getName());
    System.out.println("ID number: " + employee1.getIdNumber());
    System.out.println("Department: " + employee1.getDepartment());
    System.out.println("Position: " + employee1.getPosition());
    //create another Employee object
    Employee employee2 = new Employee();
    //test the mutator methods
    employee2.setName("Mark Jones");
    employee2.setIdNumber(39119);
    employee2.setDepartment("IT");
    employee2.setPosition("Programmer");
    System.out.println("\n***employee2***");
    System.out.println("Name: " + employee2.getName());
    System.out.println("ID number: " + employee2.getIdNumber());
    System.out.println("Department: " + employee2.getDepartment());
    System.out.println("Position: " + employee2.getPosition());
    //create another Employee object
    Employee employee3 = new Employee();
    //test the mutator methods
    employee2.setName("Joy Rogers");
    employee2.setIdNumber(81774);
    employee2.setDepartment("Manufacturing");
    employee2.setPosition("Engineer");
    System.out.println("\n***employee3***");
    System.out.println("Name: " + employee3.getName());
    System.out.println("ID number: " + employee3.getIdNumber());
    System.out.println("Department: " + employee3.getDepartment());
    System.out.println("Position: " + employee3.getPosition());
  }
}

我知道我需要添加" public static void main(String [] args)"命令某处,但我不知道在哪里! 感谢您提供任何帮助!

2 个答案:

答案 0 :(得分:0)

您正在创建两个不同的类 员工和员工信息 我假设您正在尝试执行Employee类,其中编译器无法找到Public static void main

答案 1 :(得分:0)

首先你应该编译所有' .java'文件。您可以使用命令行

来执行此操作
javac *.java 

其次,你应该经营一个主要有'主要'方法。如

java EmployeeInfo