0

I have same code

import org.apache.commons.beanutils.PropertyUtils;
public class Reflection {

    private double []masElement = {3,5,2,5};

    public double getValue(int i){
    if (masElement.length>i){
    return masElement[i];
    }
    return 0;
    }
    public void setValue(int i, int value){
    if (masElement.length>i){
        masElement[i]=value;
    }
}
    public static void main(String[] args) {
    Reflection n = new Reflection();
    try {
        System.out.println(PropertyUtils.getProperty(n, "masElement[0]"));
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }

I have problem and i don't understand why?

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.commons.beanutils.ConvertUtilsBean.<init>(ConvertUtilsBean.java:157)
at org.apache.commons.beanutils.BeanUtilsBean.<init>(BeanUtilsBean.java:117)
at org.apache.commons.beanutils.BeanUtilsBean$1.initialValue(BeanUtilsBean.java:68)
at org.apache.commons.beanutils.ContextClassLoaderLocal.get(ContextClassLoaderLocal.java:153)
at org.apache.commons.beanutils.BeanUtilsBean.getInstance(BeanUtilsBean.java:80)
at org.apache.commons.beanutils.PropertyUtilsBean.getInstance(PropertyUtilsBean.java:114)
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:426)
at same.home.reflection.Reflection.main(Reflection.java:39)
   Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 8 more

1 Answer 1

5

Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory

You need to put Apache Commons Logging JAR file in the classpath as well. The Apache Commons Beanutils is namely using it as one of its dependencies.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.