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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© eternallove 中级黑马   /  2014-5-1 17:46  /  1370 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 eternallove 于 2014-5-1 20:04 编辑
  1. public class InputSpectorTest {
  2. public static void main(String[] args){
  3. JavaBeanTest jbt = new JavaBeanTest(3,4);
  4. BeanUtils.setProperty(jbt, "birthday.time", "111");
  5. BeanUtils.setProperty(jbt, "birthday.time", "111");                System.out.println(BeanUtils.getProperty(jbt, "brithday.time"));
  6. }
  7. }
  8. import java.util.Date;

  9. public class JavaBeanTest {
  10.         private Date birthday = new Date();
  11.         private int x;
  12.         private int y;
  13. public Date getBirthday() {
  14.                 return birthday;
  15.         }
  16. public void setBirthday(Date birthday) {
  17.                 this.birthday = birthday;
  18.         }
  19. public JavaBeanTest(int x,int y){
  20.         this.x = x;
  21.         this.y = y;
  22. }
  23. public int getX() {
  24.         return x;
  25. }
  26. public void setX(int x) {
  27.         this.x = x;
  28. }
  29. public int getY() {
  30.         return y;
  31. }
  32. public void setY(int y) {
  33.         this.y = y;
  34. }
  35. }
复制代码

哥们都帮忙看看,我这个代码为什么会有异常:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/FastHashMap
        at org.apache.commons.beanutils.PropertyUtilsBean.getPropertyDescriptor(PropertyUtilsBean.java:959)
        at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1254)
        at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:790)
        at org.apache.commons.beanutils.BeanUtilsBean.getNestedProperty(BeanUtilsBean.java:709)
        at org.apache.commons.beanutils.BeanUtilsBean.getProperty(BeanUtilsBean.java:735)
        at org.apache.commons.beanutils.BeanUtils.getProperty(BeanUtils.java:380)
        at com.xy.test.InputSpectorTest.main(InputSpectorTest.java:66)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.FastHashMap
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        ... 7 more

6 个回复

倒序浏览
你的包有导入吗?总共要导入两个包,一个日志包,一个BeanUtils包
回复 使用道具 举报
榨菜 发表于 2014-5-1 18:51
你的包有导入吗?总共要导入两个包,一个日志包,一个BeanUtils包

导过了。
我用PropertyUtils可以的,为什么BeanUtils就不行呢?
回复 使用道具 举报
我用PropertyUtils可以的,为什么BeanUtils就不行呢?
回复 使用道具 举报
这是我导的两个包,是不是版本的问题啊,求解决,帮我试试你们行不行。。。我错出在哪里了?
commons-beanutils-1.9.1.jar
commons-logging-1.1.3.jar
回复 使用道具 举报
楼主啊   你犯了一个 愚蠢的错误啊   叫我怎么说你啊
把你打印结果 换成  System.out.println(BeanUtils.getProperty(jbt, "birthday.time"));  试试    看看你的birthday.time 对不对      你写成brithday.time
回复 使用道具 举报
﹊佑雨时杰↘ 发表于 2014-5-1 19:32
楼主啊   你犯了一个 愚蠢的错误啊   叫我怎么说你啊
把你打印结果 换成  System.out.println(BeanUtils ...

果然是个非常愚蠢的错误,谢谢啦,我太不细心了{:2_33:}{:3_56:}
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马