aspose file tools*
The moose likes Java in General and the fly likes Java Reflection class not found problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Reflection class not found problem" Watch "Java Reflection class not found problem" New topic
Author

Java Reflection class not found problem

andrea casini
Greenhorn

Joined: Jul 27, 2010
Posts: 13
Hello to everyone.

I am experiencing a really annoying problem when using reflection. I have this simple code:


I took this example from the official guide but when I run this in Netbeans 6.9.1 it return a "ClassNotFoundException".. WTF the class A is there!! Why is this happen?
I believe it has something to do with netbeans.

Please help.

Thanks
Markas Korotkovas
Greenhorn

Joined: Jan 27, 2011
Posts: 21

are you using default package? if not you need to specify fully qualified name for A when doing the Class.forName("...")
andrea casini
Greenhorn

Joined: Jul 27, 2010
Posts: 13
Markas Korotkovas wrote:are you using default package? if not you need to specify fully qualified name for A when doing the Class.forName("...")


Ok.. The class is in "build/classes/model/". But I don't know the sintax to specify the classpath in the "forName" method. Could you please tell me how?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

if the class is on the model directory then it should have

at the start of the class file.
The fully qualified class name is now model.A
You refer to the class in Class.forName() using the fully qualified class name ie Class.forName("model.A")
andrea casini
Greenhorn

Joined: Jul 27, 2010
Posts: 13
Damn it was so simple..

Thank you..
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

No one said things have to be hard. Reflection is a great tool.
Good job
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java Reflection class not found problem
 
Similar Threads
operators
isinstance
Short-Circuit Operators.....
how to compile java source code with assertion ?
comparing Boolean wrappers objects