我试图将一个类的所有属性复制到另一个,如下所示。该错误的根源可能是什么?

我有两个简单的Pojo,它们具有不同的类名但具有相同的属性,并在实例化两个实例后将它们从另一个复制

乌普特

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 jar添加到您的构建路径或类路径中。 BeanUtils将需要此jar。

org.apache.commons.logging

关于java - BeanUtils.copyProperties产生java.lang.VerifyError:,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27642933/

10-09 05:04