• Post Reply Bookmark Topic Watch Topic
  • New Topic

about beanutils

chen feng
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have some problem about common-beanutils.jar

i use beanutils's static method, but all of them throw Exception.

just like:

public class MyCopy {
public static void main(String[] args) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
Book book1 = new Book();
book1.setName("Jakarta Commons Cookbook");
Book book2 = new Book();

book2 = (Book)BeanUtils.cloneBean(book1);
// System.out.println(BeanUtils.getProperty(book1, "name"));

class Book {
private String name = "";

public String getName() {
return name;

public void setName(String name) {
this.name = name;


both of cloneBean and getProperty throw Exception.

Exception in thread "main" java.lang.IllegalAccessException: Class org.apache.commons.beanutils.BeanUtilsBean can not access a member of class my.test.Book with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
at java.lang.Class.newInstance0(Class.java:344)
at java.lang.Class.newInstance(Class.java:303)
at org.apache.commons.beanutils.BeanUtilsBean.cloneBean(BeanUtilsBean.java:164)
at org.apache.commons.beanutils.BeanUtils.cloneBean(BeanUtils.java:98)
at my.test.MyCopy.main(MyCopy.java:18)

Exception in thread "main" java.lang.NoSuchMethodException: Property 'name' has no getter method
at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1127)
at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:686)
at org.apache.commons.beanutils.BeanUtilsBean.getNestedProperty(BeanUtilsBean.java:698)
at org.apache.commons.beanutils.BeanUtilsBean.getProperty(BeanUtilsBean.java:723)
at org.apache.commons.beanutils.BeanUtils.getProperty(BeanUtils.java:265)
at my.test.MyCopy.main(MyCopy.java:19)

help me
Jaikiran Pai
Posts: 10447
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Book {

Shouldn't this class be public, so that this is accessible to the BeanUtils.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!