• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Java Reflection class not found problem

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 21
Mac Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No one said things have to be hard. Reflection is a great tool.
Good job
 
rubbery bacon. rubbery tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic