本帖最后由 陈国柱 于 2013-9-20 08:57 编辑
用cmd运行没问题,但是用MyEclipse运行就总是报错。总是提示:没有方法错误?什么意思?Exception in thread "main" java.lang.NoSuchMethodError: day14to17.Student.<init>(Ljava/lang/String;Ljava/lang/String;)V
at day14to17.MapDemo3.demo(MapDemo3.java:50)
at day14to17.MapDemo3.main(MapDemo3.java:78)- package day14to17;
- /*
- map 扩展知识
- map集合被使用是应为具备映射关系。
- “预热班” Student( “01” “zhangsan”)
- "预热班" Student(“02” “lisi”)
- "就业办" “01” “wangwu”
- "就业办" “02” “heliu”
- 一个学校有多个教室,每一个教室都有名称。
- */
- import java.util.*;
- class Student
- {
- private String id;
- private String name;
- Student(String id,String name)
- {
- this.id = id;
- this.name = name;
- }
- public String getId()
- {
- return id;
- }
- public String getName()
- {
- return name;
- }
- public String toString()
- {
- return id+"::"+name;
- }
- }
- class MapDemo3
- {
- public static void demo()
- {
- //List<Student>,存储学生对象。
- HashMap<String,List<Student>> czbk = new HashMap<String,List<Student>>();
- List<Student> yure = new ArrayList<Student>();//多态
- List<Student> jiuye = new ArrayList<Student>();
- czbk.put("yureban",yure);
- czbk.put("jiureban",jiuye);
- yure.add(new Student("01","zhangsan"));//这里开始不能通过,但是在cmd上运行却没问题的。
- yure.add(new Student("04","wangwu"));
- jiuye.add(new Student("01","lisi"));
- jiuye.add(new Student("02","zhaoqi"));
- Iterator<String> it = czbk.keySet().iterator();//由于czbk是HashMap类的,可以调用keySet().而它又返回一个Set,而Set有迭代器功能。
- while (it.hasNext())
- {
- String roomName = it.next();
- List<Student> room = czbk.get(roomName);
- System.out.println(roomName);
- getInfos(room);
- }
- }
- public static void getInfos(List<Student> list)
- {
- Iterator<Student> it = list.iterator();
- while (it.hasNext())
- {
- Student s = it.next();
-
- System.out.println(s);
- }
- }
- public static void main(String[] args)
- {
- demo();
- }
- }
复制代码 |