I need to create instances from each statically defined inner classes, but I get java.lang.ClassNotFoundException.
First, I collect the declared inner classes:
public String[] getInnerClassNames(Class<?> p_class) {
Class<?>[] declaredClasses = p_class.getDeclaredClasses();
String[] innerClassNames = new String[declaredClasses.length];
for (int i = 0; i < declaredClasses.length; i++) {
innerClassNames[i] = declaredClasses[i].getCanonicalName();
}
return innerClassNames;
}
where the p_class is the outer class.
Second, I do the class loading and instantiation for the given inner class name:
public Object createObjectByClassName(String p_className)
throws ClassNotFoundException, IllegalAccessException, InstantiationException {
Class<?> clazz = Class.forName(p_className);
return clazz.newInstance();
}
This inner class name has the form: PACKAGE.OUTER_CLASS_NAME.INNER_CLASS_NAME.
What I am missing here?