Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

class loading help pls!!

Status
Not open for further replies.

gotchausa

Programmer
Jan 24, 2002
64
0
0
CA
I'm trying to implement dynamic class loading using:
Class.forName(className, true, Thread.currentThread().getContextClassLoader());

Class A (which is a jar file residing in the /jre/lib/ext dir ) that I'm loading extends class B (which is packaged as a separate package with the main application). Next I invoke a method defined in class B, which class A should have access to (it being class B's child). So I do:

classInstance = classLoaded.newInstance();
Method M = classA.getMethod("methodNameinClassB", null);
M.invoke(classInstance, null);

When I execute my main class, I get the error about noSuchMethod. What am I doing wrong?

 
I expect that in this line :

Code:
Method M = classA.getMethod("methodNameinClassB", null);

your method "methodNameinClassB" does not exist - hence the error "NoSuchMethod".
 
The method exists in the class that the loaded class extends from...
 
OK, I've been testing the problems are these:

I have 2 packages X, Y.
X contains classes 1,2,3,4,5
Y contains A.

Class 1 = main class.
It loads class A.
Class A extends from Class 2 and also imports classes 3,4.

Now I install package X under classpath /a/b/c.
I place package Y under another directory (I tried hte /jre/lib/ext to make the package an extension).

When I execute Class 1 of package X, I get an error. It complains that it cant find classes 3,4 which class A (the loaded class) uses.

I even tried putting package Y in the same dir as the main class but still get the same noClassDefFound error.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top