chen feng

Greenhorn
+ Follow
since Jun 22, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by chen feng

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
16 years ago