This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes about beanutils Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "about beanutils" Watch "about beanutils" New topic
Author

about beanutils

chen feng
Greenhorn

Joined: Jun 22, 2007
Posts: 1
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
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9915
    
158

class Book {


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



[My Blog] [JavaRanch Journal]
 
jQuery in Action, 2nd edition
 
subject: about beanutils
 
Similar Threads
Is my approach right while inserting a foreign key?
Cloning Question
newbee cant find string
StaleStateException
Explation of Object Identity