Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Error loading class

807569Sep 12 2006 — edited Sep 12 2006
Hi, I've got the following code to call some classes I've created:

String className = this.request.getParameter("class_name");
className = (className==null?"":className.trim());
MySession.setAttribute(this.request, "class_name", className);

try {

Class cl = Class.forName(className);
Class pt[] = {Class.forName("javax.servlet.http.HttpServletRequest"),
Class.forName("java.io.PrintWriter")};
java.lang.reflect.Constructor cons = cl.getConstructor(pt);

Object obj[] = {this.request, this.out};
Object cont = cons.newInstance(obj);

s = ((AppHtml)cont).getHtml();

} catch (java.lang.Exception ex) {
ex.printStackTrace();
s = ex.getMessage() + "\n";
s += "Error in instance" + className + "<";
}
The problem I have is each time I try to call a class that is in the same project a classnotfound exception is thrown.

java.lang.ClassNotFoundException: AgrProducto

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1340)

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

at java.lang.Class.forName0(Native Method)

What do I need to load a class with the code above? Thanks in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 10 2006
Added on Sep 12 2006
8 comments
218 views