Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

loadClass, defineClass (run-time loading)

Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using the Reflection API

I load a class called 'SubClass' which exists in a directory called 'subdir' at run-time from my program
-------------------------------------------------------------------- ----------
CustomClassLoader loader = new CustomClassLoader();
Class classRef = loader.loadClass("SubClass");
---------------------------------------------- --------------------------------

class CustomClassLoader extends ClassLoader. I have defined 'findClass(String className)' method in CustomClassLoader.

This is what 'findClass(String className)' returns:
defineClass (className,byteArray,0,byteArray.length);

'byteArray' is of type byte[] and has the contents of subdir/SubClass.

the problem:
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?

Help appreciated in advance..
    Bookmark Topic Watch Topic
  • New Topic