MyException - 我的异常网
当前位置:我的异常网» Eclipse » thread "main" java.lang.Error: Unresol

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

www.MyException.Cn  网友分享于:2013-11-26  浏览:9490次
大侠帮忙看看,这哪里出错了
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);

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有