Я пытаюсь просто скопировать все свойства одного класса в другой, как показано ниже. Что может быть причиной этой ошибки?
У меня есть два простых 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;
}
}
добавьте эту банку Apache в свой путь сборки или путь к классу. BeanUtils понадобится эта банка.
org.apache.commons.logging