It's not a secret anymore!
The moose likes Java in General and the fly likes Related to java.lang.Reflect package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Related to java.lang.Reflect package" Watch "Related to java.lang.Reflect package" New topic

Related to java.lang.Reflect package

Indravadan T Patel

Joined: Sep 09, 2007
Posts: 29

I am trying to create the runtime object using the Constructor and Class. The code is just like that :

And i get the error :
Exception in thread "main" java.lang.ClassNotFoundException: A
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at indra.Test.main(
Java Result: 1

Please let me know why that happens.

Indravadan Patel
[ July 10, 2008: Message edited by: David O'Meara ]
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Please format your code and use code tags.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

You haven't really provided the details but
at indra.Test.main(

says that your Test class has been packaged as 'indra', is the Class 'A' also packaged as 'indra'?
Class.forName requires the fully qualified class name, hence Class.forName("indra.A")
I agree. Here's the link:
subject: Related to java.lang.Reflect package
It's not a secret anymore!