• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

java class loader basic question..  RSS feed

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, i have a basic java class loader question here,

with com.mycompany.app.class1, is the path of a class which i intend to load and its inside the same package as my current class.
But the class 'c' loaded is always null, perhaps this is not the correct way? The following is the content customclassloader.java which i get from some resources on the internet.



Please guide or help or comment, thanks in advance.
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


}catch(Exception e){
return null;
}


You need to put in some proper error handling, like at least notifying you if there is a problem.

I'm also not quite sure what the point of this ClassLoader is - after a cursory inspection it seems to look at the classpath, so any classes would be loaded by the standard classloaders, and never by the loadClassData method.

String classPath = ((String)ClassLoader.getSystemResource(className.replace('.',File.separatorChar)+".class").getFile()).substring(1);


This line looks rather strange to me; what's it supposed to do?

I'll move this to the Intermediate forum - loading classes is not beginner stuff.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!