日期:2014-05-20  浏览次数:20871 次

求解!!!!!
import java.util.*;
public class Mapshiyan24 {
public static void main(String args[]){
  Map employers=new LinkedHashMap(10,0.75f,true);
  employers.put("1111-01",new Employer("zhang",26,"male","manager",3000f));
  employers.put("1111-02",new Employer("li",25,"male","leader",2000f));
  employers.put("1111-03",new Employer("wang",24,"male","employer",1000f));
  employers.put("1111-04",new Employer("zhao",24,"famale","employer",1000f));
   
  Set set =employers.entrySet();
  Iterator iterator=set.iterator();
  for(int i=0;i<employers.size();i++){
  if(iterator.hasNext()){
  Map.Entry me=(Map.Entry)iterator.next();
  Employer employer=(Employer)me.getValue();
  System.out.println("The information of employer["+i+"]:");
  System.out.println("Key in map is: "+me.getKey());
  System.out.println("Name:"+employer.getName());
  System.out.println("Age:"+employer.getAge());
  System.out.println("Sex:"+employer.getSex());
  System.out.println("Post:"+employer.getPost());
  System.out.println("Salary: "+employer.getSalary());
  System.out.println();
   
  }
   
  }
  Employer a=(Employer)employers.get("1111-04");
  System.out.println(a.getName());
System.out.println("Name:"+a.getName());
System.out.println("Age:"+a.getAge());
System.out.println("Sex:"+a.getSex());
System.out.println("Post:"+a.getPost());
System.out.println("Salary: "+a.getSalary());
System.out.println();
}
}

class Employer{
private String name;
private int age;
private String sex;
private String post;
private float salary;
public Employer(){}
public Employer(String name,int age,String sex,String post,float salary)
{
this.name=name;
this.age=age;
this.sex=sex;
this.post=post;
this.salary=salary;

}
public String getName(){return name;}
public void setName(String str){this.name=str;}
public int getAge(){return age;}
public void setAge(int age){this.age=age;}
public String getSex(){return sex;}
public void setSex(String sex){this.sex=sex;}
public String getPost(){return post;}
public void setPost(String post){this.post=post;}
public float getSalary(){return salary;}
public void setSalary(float salary){this.salary=salary;}

}

它说 class Employer 已定义了。 是哪里错了???? 求各位大神求解

------解决方案--------------------
同一个包下,其它文件里定义过?
------解决方案--------------------
跑了一下,没问题
可能是1楼说的问题
楼主自己检查一下