> The program runs fine if SubClass does not extend any class.
> If however, SubClass extends another class, the program throws a
> NoClassDefFoundError. How does one take care of the inheritance here?
> Things to think about:
>
[quoted text clipped - 7 lines]
> What are the package names of the various classes ? Does your classloader know
> how to map package names onto directory names ?
Hey Thanks!
it is a customized class loader. The file to be loaded(SubClass.java)
is in a directory (subdir). class SubClass extends class 'SuperClass'
also defined in SubClass.java
something like this:
-----------------------------------------------------------------
class SuperClass {
public int cadence;
public int gear;
public int speed=7;
public SuperClass(int startCadence, int startSpeed, int startGear)
{
gear = startGear;
cadence = startCadence;
speed = startSpeed;
}
}
public class SubClass extends SuperClass {
public int seatHeight;
public SubClass(int startHeight, int startCadence, int startSpeed,
int startGear) {
super(startCadence, startSpeed, startGear);
seatHeight = startHeight;
}
public void disp() {
System.out.println(" Speed : " + speed);
System.out.println("hi!");
}
}
----------------------------------------------------------------------
i get the NoClassDefFoundError for SuperClass. If however, I remove
the inheritance(SuperClass) and just keep the SubClass, The loader
works fine.Do I have to separately load the SuperClass as well?
Chris Uppal - 11 Apr 2007 10:11 GMT
[me:]
> > What classloader should load the superclass ?
> >
[quoted text clipped - 6 lines]
> > What are the package names of the various classes ? Does your
> > classloader know how to map package names onto directory names ?
[...]
> it is a customized class loader. The file to be loaded(SubClass.java)
> is in a directory (subdir). class SubClass extends class 'SuperClass'
> also defined in SubClass.java
You haven't really addressed the questions I suggested that you thought about.
For instance (only one example), /which/ classloader is expected to load
SuperClass ? (SuperClass, BTW, will be loaded automatically as a side-effect
of attempting to load SubClass). Where is that classloader /supposed/ to be
looking for the .class file ? Where /is/ the .class file ?
Remember that it's your responsibility (or rather, it's your classloader's
responsibility) to take the class name, and deduce where to find the
classfile -- the classloading framework provides /no/ help with that (it can't,
because there is no defined connection between class names and file names).
-- chris
enzo.660@gmail.com - 11 Apr 2007 16:45 GMT
> You haven't really addressed the questions I suggested that you thought about.
>
[quoted text clipped - 7 lines]
> classfile -- the classloading framework provides /no/ help with that (it can't,
> because there is no defined connection between class names and file names).
nevermind Chris. i figured it out on Sun forums. I had to load the
SuperClass separately!
Thanks!