• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Got Exception=> Class.forName(String ClassName) throwing ClassNotFoundException

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
My code below -

So as you can see, I am trying to create the object of the class which i get as a string , and try to create the object of that class using Class.forName(String) but it throws ClassNotFoundException.
I go this in the sun's documentation as =>


-----------------------------------------------------------------------------
forName
Throws:
LinkageError - if the linkage fails
ExceptionInInitializerError - if the initialization provoked by this method fails
ClassNotFoundException - if the class cannot be located
-----------------------------------------------------------------------------


So it means if the JVM could not locate the class then it will throw the class not found exception, but here i can i created the class ans can also see the compiled class file for the same, that too in proper directory.
So please help me to figure out the reason behind this, which has stopped my development work completely.

Thanks & regards,
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The class name needs to be a fully-qualified name (e.g., "com.whatever.Foo") and the class file needs to available to the application classloader (i.e., on the class path.) If you meet both of these criteria, then it'll work; if you don't, then it won't.
 
netali joshef
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ernest Friedman-Hill wrote:The class name needs to be a fully-qualified name (e.g., "com.whatever.Foo") and the class file needs to available to the application classloader (i.e., on the class path.) If you meet both of these criteria, then it'll work; if you don't, then it won't.


hey Ernest Friedman-Hill!
Can you elaborate it more.Is that for this code to execute both of them should be in the same package or else I will have to provide the absolute path for the class of which object I am trying to create the object there?
 
netali joshef
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also tried to print the stack trace like below -
but getting similar exception like output on the cmd and not the print of Stack Trace.

Can anybody figure out the reason behind this...
???
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

pritam mugal wrote:
Is that for this code to execute both of them should be in the same package or else I will have to provide the absolute path for the class of which object I am trying to create the object there?



Nope, and nope. You need to use the fully qualified name of the class and it needs to be on the classpath. Are both of these things true in your example?
 
netali joshef
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please check my code above where exception arises.So how can i use the complete class name,its been getting from the function return as a string.
And about classpath do you mean the system classpath?Please explain me this more
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If this.cli.getParserConfigImpl() does not return the fully qualified name of the class that method is flawed, and needs to be fixed. "String", "List" and "File" are not class names - the real class names are "java.lang.String", "java.util.List" (or "java.awt.List") and "java.io.File".
 
netali joshef
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it seems that, i am not successful in explaining you the problem.
I was worried about the object creation of RealEstateCoParserConfiguration implementation during runtime.
And i think i solved it, using



but now hitting with another error -

I need to close this and start a new thread for this now..?
But I am not willing to close this unless I am confident about the solution to previous problem Class not found exception
 
netali joshef
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
once i seen about this is the best java forum on some ibm blog...
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

pritam mugal wrote:once i seen about this is the best java forum on some ibm blog...



Then I guess you're done -- as if the best can't solve your problem, your problem is not solveable...


Seriously though, think of us as yourself, if some stranger came to you with a problem that you know little about, and you have to volunteer to help. If you posted that to yourself, would you have bothered?

Maybe isolating the problem would help a bit. Maybe writing a very small self contained compilable example (that shows the problem) would help a bit. Maybe being a bit nicer would help too.

Henry
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The RuntimeException about uncompilable code is what happens when you tell Eclipse "Run anyway" when it asks you "Errors exist in project, run anyway?" You have to fix all the compile errors in your project before running it.

In any case, I agree with what Henry said. We can't read your mind. It looks like you've got a large, complex inherited code base that you don't understand, and you're having some issues that you have not adequately explained. As soon as we start to discuss one issue, you shift to a different, apparently unrelated issue, so we don't know if you understood and fixed the first one, or if you're just stumbling about, breaking different things.

We would like to help, but you have to help us to help you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic