A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 逍遥呆 中级黑马   /  2014-9-19 10:10  /  912 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

运行之后会出现
Exception in thread "main" java.lang.NoSuchMethodError: Person.<init>(Ljava/lang/String;I)V
        at EnumTest.main(EnumTest.java:9)
  1. public class EnumTest
  2. {
  3.         public static void main(String[] args)          //throws IOException
  4.         {
  5.                 ArrayList al = new ArrayList();
  6.                 al.add(new Person("lisi01",25));
  7.                 al.add(new Person("lisi02",43));
  8.                 al.add(new Person("lisi03",24));
  9.                 al.add(new Person("lisi04",17));
  10.                 Iterator it = al.iterator();
  11.                 while(it.hasNext())
  12.                 {
  13.                         Person p = (Person)it.next();
  14.                         System.out.println(p.getName()+p.getAge());
  15.                 }
  16.         }


  17. }
  18. class Person
  19. {
  20.         private String name;
  21.         private int age;
  22.         Person(String name,int age)
  23.         {
  24.                 this.name = name;
  25.                 this.age = age;
  26.         }
  27.         public String getName()
  28.         {
  29.                 return name;
  30.         }
  31.         public int getAge()
  32.         {
  33.                 return age;
  34.         }
  35. }
复制代码

6 个回复

倒序浏览
编译出现警告 运行正常
回复 使用道具 举报
只是提醒你泛型类没有指定类型。
改成,ArrayList<Object> al = new ArrayList<Object>();
不改也没问题。
回复 使用道具 举报
xplcc 发表于 2014-9-19 13:17
编译出现警告 运行正常

可是我拿myEclipse运行,死活也不让我过
回复 使用道具 举报
cs8630323 发表于 2014-9-19 15:58
只是提醒你泛型类没有指定类型。
改成,ArrayList al = new ArrayList();
不改也没问题。 ...

我那个编译过不去啊
回复 使用道具 举报
我编译运行没错,有没有导入util,你搜索下这个错误名吧
回复 使用道具 举报
cs8630323 发表于 2014-9-20 01:13
我编译运行没错,有没有导入util,你搜索下这个错误名吧

谢谢,我这次成功了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马