tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Randall Parker" <>
Subject Re: why ClassNotFoundException on attempt to dynamically load a class?
Date Mon, 21 Feb 2000 22:34:55 GMT

If "SpecificReport" is part of a package then if you are importing that package into the class
where you are doing this then this line will work. There is an implicit package name the compiler
can search 
for to add to what you see on that line:
 >   SpecificReport aSpecificReport = new SpecificReport();

But in this case the run-time will not know about the package name:
 >String dynamicReportName = "SpecificReport";
 >myReport = (myReportInterface)Class.forName(dynamicReportName).newInstance();

On Mon, 14 Feb 2000 16:47:17 -0800, Daniel Kehoe wrote:

>Why does this code throw an exception 
>"java.lang.ClassNotFoundException: SpecificReport"?
>String dynamicReportName = "SpecificReport";
>myReport = (myReportInterface)Class.forName(dynamicReportName).newInstance();
>It works fine if I just instantiate the object:
>SpecificReport aSpecificReport = new SpecificReport();
>And it works fine under Jserv or Jrun.
>I hear someone asking, why does he want to do this? Answer: I want to 
>load a class dynamically based on a parameter passed from the 
>browser, like:
>String dynamicReportName = request.getParameterValues("report")[0];
>I'm using Tomcat 3.1M1 with java 1.2.2 Classic VM (build 
>Linux_JDK_RC3, native threads, sunwjit). What's going on that's 
>To unsubscribe, e-mail:
>For additional commands, e-mail:

View raw message