我试图简单地将一个类的所有属性复制到另一个类,如下所示。可能是这个错误的根源是什么?
我有两个简单的Pojos,它们具有不同的类名但具有相同的属性,并且在实例化两个之后从另一个中复制一个
12-25 04:24:33.380 23062-23062/com.example.somghosh.earthmiles I/System.out﹕ *** Before BeanUtils.copyProperties ***
12-25 04:24:33.380 23062-23062/com.example.somghosh.earthmiles I/System.out﹕ Person
12-25 04:24:33.380 23062-23062/com.example.somghosh.earthmiles I/System.out﹕ 15
12-25 04:24:33.380 23062-23062/com.example.somghosh.earthmiles I/System.out﹕ rene
12-25 04:24:33.380 23062-23062/com.example.somghosh.earthmiles I/System.out﹕ othePerson
12-25 04:24:33.380 23062-23062/com.example.somghosh.earthmiles I/System.out﹕ 100
The actual copy code produces error :
Process: com.example.somghosh.earthmiles, PID: 23479
java.lang.VerifyError: org/apache/commons/beanutils/PropertyUtilsBean
at org.apache.commons.beanutils.BeanUtilsBean.<init>(BeanUtilsBean.java:112)
at org.apache.commons.beanutils.BeanUtilsBean$1.initialValue(BeanUtilsBean.java:63)
at org.apache.commons.beanutils.BeanUtilsBean$1.initialValue(BeanUtilsBean.java:59)
at org.apache.commons.beanutils.ContextClassLoaderLocal.get(ContextClassLoaderLocal.java:154)
at org.apache.commons.beanutils.BeanUtilsBean.getInstance(BeanUtilsBean.java:75)
at org.apache.commons.beanutils.BeanUtils.copyProperties(BeanUtils.java:135)
at com.example.somghosh.earthmiles.views.MainActivity.afterViews(MainActivity.java:99)
at com.example.somghosh.earthmiles.views.MainActivity_.onViewChanged(MainActivity_.java:87)
at org.androidannotations.api.view.OnViewChangedNotifier.notifyViewChanged(OnViewChangedNotifier.java:41)
at com.example.somghosh.earthmiles.views.MainActivity_.setContentView(MainActivity_.java:48)
at com.example.somghosh.earthmiles.views.MainActivity_.onCreate(MainActivity_.java:38)
import org.apache.commons.beanutils.BeanUtils;
Person person = new Person();
person.setAge(15);
person.setName("rene");
OtherPerson othePerson = new OtherPerson();
System.out.println("*** Before BeanUtils.copyProperties ***");
System.out.println("Person");
System.out.println(person.getAge());
System.out.println(person.getName());
System.out.println("othePerson");
System.out.println(othePerson.getAge());
System.out.println(othePerson.getName());
//copy properties from (target, source)
try {
BeanUtils.copyProperties(othePerson, person);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
System.out.println("\n*** After BeanUtils.copyProperties ***");
System.out.println("Person");
System.out.println(person.getAge());
System.out.println(person.getName());
System.out.println("othePerson");
System.out.println(othePerson.getAge());
System.out.println(othePerson.getName());
class Person {
private String name;
private int age;
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;
}
Person(){
name = "Person";
age = 1;
}
}
class OtherPerson {
private String name;
private int age;
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;
}
OtherPerson(){
name = "OtherPerson";
age = 100;
}
}
答案 0 :(得分:0)
将此Apache jar添加到构建路径或类路径中。 BeanUtils将需要这个jar。
org.apache.commons.logging