Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

loadClass, defineClass (run-time loading)

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey!
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..
Thanks!
reply
    Bookmark Topic Watch Topic
  • New Topic