| | |
Class.forName(String ClassName) throwing ClassNotFoundException
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2009
Posts: 39
Reputation:
Solved Threads: 0
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 wil throw the class not found exception, but here i can i created the class ans can also see the compiled clasfile for the same, that too in proper directory.
So plz help me toi figure out the reason behind this, which has stopped my development work completely.
Thanks & regards,
Multicoder
My code below
-•
•
•
•
String parserConfigurationClassName = this.cli.getParserConfigImpl();//Gets implementation's name as a string
Class parserConfigurationClass;
try {
parserConfigurationClass = Class.forName(parserConfigurationClassName);
}
catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Failed to load parserConfigImpl [" + parserConfigurationClassName + "]: Class not found");
}
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 wil throw the class not found exception, but here i can i created the class ans can also see the compiled clasfile for the same, that too in proper directory.
So plz help me toi figure out the reason behind this, which has stopped my development work completely.
Thanks & regards,
Multicoder
The class was loaded in another ClassLoader, seemingly, and now you are trying to load it using the context classloader. That doesn't work.
The thread that is doing this will need to use the setContextClassLoader (see Thread) method, and the getClass().getClassLoader() method of the "loaded" class. Then this should work.
The real question is, though, why do you need the Class at this point? If this is some sort of plugin architecture, then I can only assume that this Class (the one that is attempting to load the other), is part of the "framework". And, if that is so, it should only be working within the defined interface that the plugin is to adhere to.
The thread that is doing this will need to use the setContextClassLoader (see Thread) method, and the getClass().getClassLoader() method of the "loaded" class. Then this should work.
The real question is, though, why do you need the Class at this point? If this is some sort of plugin architecture, then I can only assume that this Class (the one that is attempting to load the other), is part of the "framework". And, if that is so, it should only be working within the defined interface that the plugin is to adhere to.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Jun 2009
Posts: 39
Reputation:
Solved Threads: 0
Hi,
I checked with setContextClassLoader(), but to tel u i m not creating any extra thread.
Only the main thread running all around the execution and the class for which i am trying to load is part of the application framework,
But which class to load is passed as cmd param and accordignly need to create the object of that class.
So I cant figure out any issue with the class loader..??
plz clarify me...!
I checked with setContextClassLoader(), but to tel u i m not creating any extra thread.
Only the main thread running all around the execution and the class for which i am trying to load is part of the application framework,
But which class to load is passed as cmd param and accordignly need to create the object of that class.
So I cant figure out any issue with the class loader..??
plz clarify me...!
Change that catch block to also do a printStackTrace() and then post the complete exception.
Also post the "classpath" in use (most likely not the System classpath). Then also post the full path to the class to be loaded.
Also post the "classpath" in use (most likely not the System classpath). Then also post the full path to the class to be loaded.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Jun 2009
Posts: 39
Reputation:
Solved Threads: 0
hi,
I believe the exception.printStackTrace()
prints the the contents of the system.err to the standard error output system i.e. to cmd
so is this right?then this is my output on cmd -
classpath at the point of execution (i.e.path for the class where the above code gets called) is - and the classpath to the class which trying to get load is -
i think this will reveal the package structure also..
waiting for ur reply
I believe the exception.printStackTrace()
prints the the contents of the system.err to the standard error output system i.e. to cmd
so is this right?then this is my output on cmd -
•
•
•
•
Error: Failed to load parserConfigImpl [au.com.allhomes.listing.harvester.parse.
RealEstateCoParserConfiguration]: Class not found
java ListingTestHarness <options>
Where options include:
--inputHtml <htmlFile> The HTML file to parse.
--listingType <residentialSale | commercialSale | businessSale | ruralSale |
residentialRental | commercialRental>
--parserConfigImpl <parserConfigImpl> The parser configuration to use.
--parserClassImpl <parserClassImpl> [Optional]: The parser class to use.
--urlConfigFile <urlConfigFile> A mapping of remote URLs to local te
st resources.
--pageType <listingPage | searchPage> The type of HTML page being harvested.
•
•
•
•
com.allhomes.listing.harvester.harness.ListingTestHarnessConfiguration.java
•
•
•
•
com.allhomes.listing.harvester.parse.RealEstateCoParserConfiguration.java
waiting for ur reply
The au is definately significant, but the stuff printed is neither the "printstacktrace" that was asked for, nor the classpath, nor the fullpath to the classfile.
@OP before you start playing around with classloaders and reflection learn what the classpath is, and how to use it, and learn the "tools" (i.e. java and javac) and the options (and their effects) that affect the classpath.
@OP before you start playing around with classloaders and reflection learn what the classpath is, and how to use it, and learn the "tools" (i.e. java and javac) and the options (and their effects) that affect the classpath.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Jun 2009
Posts: 39
Reputation:
Solved Threads: 0
The au seem to be significant here because my mistake in providing the package structure, but its not actually!
I configured the project in netbeans again to see it holds the parent directory "au" also.
So 'au' is the parent directory for all and inside it starts from 'com'.
I executed again but got the same exception.
•
•
•
•
@OP before you start playing around with classloaders and reflection learn what the classpath is, and how to use it, and learn the "tools" (i.e. java and javac) and the options (and their effects) that affect the classpath.
I know very wel abt both the tools but m not executing it from netbeans so that i can set the parameters i need to pass each time easily.
So at the cmd only moving to project's source directory (which is C:\Harvester) where the netbeans is putting compiled code and
not playing around with the classapth.
I know the significance of classpath.
Plz correct me further?
![]() |
Similar Threads
- java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver (Java)
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver (Java)
- error: The value for the useBean class attribute is invalid (JSP)
- JDBC Driver for SQL Server 2005, Class not found Exception (Java)
- org.apache.jasper.JasperException: Unable to load class for JSP (JSP)
- Help with displaying text through GUI interface (Java)
- resultset updatable (Oracle)
- MySQL drivers not loading? (Java)
- Trying to overload + for class to add to string 'is illegal' (C)
Other Threads in the Java Forum
- Previous Thread: null pointer exception problem
- Next Thread: How can login the remote system using java
Views: 2662 | Replies: 26
| Thread Tools | Search this Thread |
Tag cloud for Java
6 @param android api apple applet application arguments array arrays automation binary bluetooth bold c++ chat class classes client code component coordinates database datagram doctype draw eclipse educational error event exception file fractal froglogic game givemetehcodez graphics gui helpwithhomework html ide ideas image ingres input integer internet intersect ip j2me java javaexcel javaprojects jmf jni jpanel jtextarea julia linux list loop map method methods mobile netbeans newbie nextline number object oracle pong print problem program programming project recursion recursive scanner screen sell server set size sms socket sort sql string swing test threads time transfer tree user web websites windows






