Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 静态错误:此类没有接受字符串[]的静态void main方法。_Java_String_Class_Static - Fatal编程技术网

Java 静态错误:此类没有接受字符串[]的静态void main方法。

Java 静态错误:此类没有接受字符串[]的静态void main方法。,java,string,class,static,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 nu

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

`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());
  }
}
我知道我需要在某个地方添加“publicstaticvoidmain(String[]args)”命令,但我不确定在哪里!
谢谢你能给予的任何帮助

您正在创建两个不同的类 雇员和雇员信息
我假设您正在尝试执行Employee类,而编译器无法找到公共静态void main

您正在创建两个不同的类 雇员和雇员信息
我假设您试图执行Employee类,其中编译器无法找到公共静态void main

首先,您应该编译所有的.java文件。您可以使用命令行作为

javac *.java 
其次,您应该运行具有“main”方法的类。作为

java EmployeeInfo

首先,您应该编译所有的“.java”文件。您可以使用命令行作为

javac *.java 
其次,您应该运行具有“main”方法的类。作为

java EmployeeInfo

您已经在
EmployeeInfo
中找到了
main
。你打算怎么办?(我可以运行你的代码,对我来说效果很好)我正在使用Dr.Java,我将文件保存为一个名为EmployeeInfo的USB驱动器上的.Java文件。我按compile,没有问题,按run,我得到一个错误。你已经在
EmployeeInfo
中找到了
main
。你打算怎么办?(我可以运行你的代码,对我来说效果很好)我正在使用Dr.Java,我将文件保存为一个名为EmployeeInfo的USB驱动器上的.Java文件。我按编译,没有问题,按运行,我得到一个错误。