Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

About ClassLoder  RSS feed

 
Steven Lau
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can load uer-defined class by default ClassLoder???

try {
Class.forName(className);
} catch (ClassNotFoundException cnfe) {
URL[] urls = new URL[]{---classPath---};
try {
URLClassLoader cl = new URLClassLoader(urls);
Class c = cl.loadClass(className);

c.newInstance(); //Error.
Class.forName(className, false, cl); //ok.
Class.forName(className); //Error.

} catch (Exception e) {
throw cnfe;
}
}

3ks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!