Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Class.forName() on inner classes

807605Jun 16 2007 — edited Jun 16 2007
I am attempting to do something like this:

class A {
...
static class B {
...
}

}

B ojb = (B)createObject(A.B)

...
public static Object createObject(String className) throws ClassNotFoundException {
Object object = null;
try {
Class classDefinition = Class.forName(className);
JOptionPane.showMessageDialog(null,"got here");
object = classDefinition.newInstance();
JOptionPane.showMessageDialog(null,"got here2");
} catch (InstantiationException e) {
System.out.println(e);
} catch (IllegalAccessException e) {
System.out.println(e);
}
JOptionPane.showMessageDialog(null,"got here 3");
return object;
}



The method executes and returns fine but when I attempt to perform the cast, I get a the classNotFoundException. What would be causing it?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 14 2007
Added on Jun 16 2007
3 comments
205 views