求助Exception in thread "main" java.lang.NullPointerException错误解决
本帖最后由 dlnb526 于 2020-2-6 22:55 编辑///CoreJAVA 4-2
import java.time.*;
public class EmployeeTest
{
public static void main(String[] args)
{
Employee[] staff = new Employee;
staff = new Employee("Carl Cracker",75000,1987,12,15);
staff = new Employee("Harry Havker",50000,1989,10,1);
for(Employee e:staff)
e.raiseSalary(5);
for(Employee e:staff)
System.out.println("name="+e.getName()+",salary="+e.getSalary()+",hireDay="+e.getHireDay());
}
}
class Employee
{
private String name;
private double salary;
private LocalDate hireDay;
public Employee(String n,double s,int year,int month,int day)
{
name = n;
salary = s;
hireDay = LocalDate.of(year, month, day);
}
public String getName()
{
return name;
}
public double getSalary()
{
return salary;
}
public LocalDate getHireDay()
{
return hireDay;
}
public void raiseSalary(double byPercent)
{
double raise = salary*byPercent/100;
salary += raise;
}
}
错误如下
Exception in thread "main" java.lang.NullPointerException
at EmployeeTest.main(EmployeeTest.java:15)
就是这里:for(Employee e:staff)
e.raiseSalary(5);
可是没有需要赋值的地方了啊~~求各位大佬帮助 知道问题在哪了,少了一组数据{:5_104:}
页:
[1]