这是我的javaBean
package com.xiaoqiang.domain;
public class User {
private String name;
public User() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public User(String name) {
this.name = name;
}
public String toString() {
return "User [name=" + name + "]";
}
}
这是我的测试类
package com.xiaoqiang.beanutils;
import com.sun.org.apache.commons.beanutils.BeanUtils;
import com.xiaoqiang.domain.User;
public class BeanUtilsDemo {
public static void main(String [] args){
System.out.println("------------------");
User u = new User();
try {
u.setName("123");
System.out.println(u);
BeanUtils.setProperty(u, "name", "jack");
} catch (Exception e) {
e.printStackTrace();
}
}
}
这是异常信息
------------------
User [name=123]
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.xiaoqiang.beanutils.BeanUtilsDemo.main(BeanUtilsDemo.java:14)
Caused by: com.sun.org.apache.commons.logging.LogConfigurationException: com.sun.org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException) (Caused by com.sun.org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException))
at com.sun.org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:543)
at com.sun.org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
at com.sun.org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
at com.sun.org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
at com.sun.org.apache.commons.beanutils.BeanUtils.<clinit>(BeanUtils.java:111)
... 1 more
Caused by: com.sun.org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException (Caused by java.lang.NullPointerException)
at com.sun.org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:397)
at com.sun.org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
... 5 more
Caused by: java.lang.NullPointerException
at com.sun.org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:374)
... 6 more
------解决方案--------------------
com.sun.org.apache.commons.beanutils.BeanUtils;这个包应该是使用错了。应该是org.apache.commons.beanutils.BeanUtils;
------解决方案--------------------
初始化异常,到网上找找资料,应该可以找到的