• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Reflection class not found problem

 
andrea casini
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you using default package? if not you need to specify fully qualified name for A when doing the Class.forName("...")
 
andrea casini
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Damn it was so simple..

Thank you..
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No one said things have to be hard. Reflection is a great tool.
Good job
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic