当前位置: 代码迷 >> Eclipse >> thread "main" java.lang.Error: Unresolved compilation problems:
  详细解决方案

thread "main" java.lang.Error: Unresolved compilation problems:

热度:181   发布时间:2016-04-23 14:02:13.0
大侠帮忙看看,这哪里出错了
import java.util.*;
public class EmployeeTest 
{
public static void main(String[] args)
{
//fill the staff array with three Employee objects
Employee[] staff = new Employee[3];

staff[0] = new Employee ("Carl Cracker",75000,1987,12,15);
staff[1] = new Employee ("Harry Hacker",50000,1989,10,1);
staff[2] = new Employee ("Tony Tester",40000,1990,3,15);

//raise everyone's salary by 5%
for (Employee e : staff)
e.raiseSalary(5);

//print out information about all Employee objects
for (Employee e :staff)
System.out.println("name="+e.getName()+",salary="+e.getSalary()+",hireDay="+e.getHireDay());
}
class Employee 
{
public Employee(String n, double s, int year,int month,int day)
{
name=n;
salary=s;
GregorianCalendar = new GregorianCalendar(year,month,-1,day);
//GregorianCalendar uses o for Januanry
hireDay = calendar.getTime();
}

public String getName()
{
return name;
}

public double getSalary()
{
return salary;
}

public Date getHireDay()
{
return hireDay;
}
public void raiseSalary(double bypercent)
{
double raise =salary *bypercent/100;
salary+=raise;
 
}
 
private String name;
private double salary;
private Date hireDay;
}
}
运行的时候:出现以下提示:
Exception in thread "main" java.lang.Error: Unresolved compilation problems
  No enclosing instance of type EmployeeTest is accessible. Must qualify the allocation with an enclosing instance of type EmployeeTest (e.g. x.new A() where x is an instance of EmployeeTest).
No enclosing instance of type EmployeeTest is accessible. Must qualify the allocation with an enclosing instance of type EmployeeTest (e.g. x.new A() where x is an instance of EmployeeTest).
No enclosing instance of type EmployeeTest is accessible. Must qualify the allocation with an enclosing instance of type EmployeeTest (e.g. x.new A() where x is an instance of EmployeeTest).

at EmployeeTest.main(EmployeeTest.java:11)


------解决方案--------------------
LZ基本功不行啊

GregorianCalendar = new GregorianCalendar(year,month,-1,day);

改为

GregorianCalendar calendar = new GregorianCalendar(year,month,day);
  相关解决方案