}
}
//一个标准的javabean类
class Person1{
private String name;
private int age;
private Date birthday;
private int y;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
}
导入第三方jar包
我已经成功导入第三方jar包,为甚么还是会抛出异常?
异常信息:
Exception in thread "main" java.lang.reflect.InvocationTargetException: Cannot set age
at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1017)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:456)
at cn.itcast.introspector.BeanUtilsTest.main(BeanUtilsTest.java:14)
Caused by: java.lang.NoSuchMethodException: Property 'age' has no setter method in class 'class cn.itcast.introspector.Person1'
at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2128)
at org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1948)
at org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:2054)
at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1015)
... 2 more
嗯,等你的回复。作者: 陈军 时间: 2012-10-16 12:27
我运行了下,。。结果我的找不到那个类。
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.commons.beanutils.ConvertUtilsBean.<init>(ConvertUtilsBean.java:157)
at org.apache.commons.beanutils.BeanUtilsBean.<init>(BeanUtilsBean.java:117)
at org.apache.commons.beanutils.BeanUtilsBean$1.initialValue(BeanUtilsBean.java:68)
at org.apache.commons.beanutils.ContextClassLoaderLocal.get(ContextClassLoaderLocal.java:153)
at org.apache.commons.beanutils.BeanUtilsBean.getInstance(BeanUtilsBean.java:80)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:456)
at basic.program.test.Basic5.main(Basic5.java:15)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
继续看看作者: 舒远 时间: 2012-10-16 12:32
我上面的回答错了。字符串12或者数字12都是可以的。
你的程序无法运行是因为你的Person1类不是public的。作者: 陈军 时间: 2012-10-16 13:08