• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

about beanutils

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

closeBean:
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)



getProperty:
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
thanks
chen
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

class Book {



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

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic