Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java BeanUtils:如何设置父类中字段的值?_Java_Parent_Apache Commons Beanutils - Fatal编程技术网

Java BeanUtils:如何设置父类中字段的值?

Java BeanUtils:如何设置父类中字段的值?,java,parent,apache-commons-beanutils,Java,Parent,Apache Commons Beanutils,我还有下一节课: public class A { private int i; public void setI(int i){...} } public class B extends A { private int c; public void setC(int c){...} } 当我尝试使用setProperty时: B b = new B(); PropertyUtils.setProperty(b, "i", 1); 我得到下一个错误: jav

我还有下一节课:

public class A {
    private int i;
    public void setI(int i){...}
}

public class B extends A {
    private int c;
    public void setC(int c){...}
}
当我尝试使用setProperty时:

B b = new B();
PropertyUtils.setProperty(b, "i", 1);
我得到下一个错误:

java.lang.NoSuchMethodException: Property 'i' has no setter method in class 'class org.test.B'
但如果我试图给B类中的字段赋值:

B b = new B();
PropertyUtils.setProperty(b, "c", 1);
一切都好。 所以,只有当我试图给父类中声明的字段赋值时,才会出现错误。
有人能帮忙吗?有没有可能像我试着用小海狸做的那样?

已经试过了,效果很好。您使用哪个版本?java 1.7,commons beanutils 1.9.1运行良好。。。你们有二传手吗?见@PaulVargas yeap,它是公共的,在父类中进行了描述。使用文件
commons logging.properties
和一行
org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
以及文件
SimpleLog.properties
和一行
org.apache.commons.logging.SimpleLog.defaultlog=all
,以查看在控制台日志中搜索setter的过程。类路径中的两个文件(默认包)。