PDA

View Full Version : [java] ClassLoader


mickey
26th July 2008, 20:35
Hello,

I need to use ClassLoader;
For instance, I've got this problem:

Class t = Class.forName("java.lang.Thread");
Class c = Class.forName("myclass.class") ;

The first works fine; the second launch an exception (it says file not found); the file is in the directory of project; I tried to move it to \bin dir, but the same
Besides, could anyone suggest me any fine link? (java api doens't like to me)....

Thanks to all

marcel
26th July 2008, 23:56
The parameter to Class.forName is not the compiled class file, but the class name, where you need to prefix the package name.

Just use google for in-depth explanations.

mickey
27th July 2008, 01:12
I've just see it....but "MyClass" (the name only I know) isn't in any package; this class isn't part a my project; it's a class that I created my own from an editor....

marcel
27th July 2008, 22:27
Then you can add this class to the class path... either by using a meta info file or just by packaging it to a jar and adding it to the global CLASSPATH env var.

mickey
28th July 2008, 02:23
hello,
yes that the problem; but how solve from program?
See at this similar problem:

class myClass {
URL D = this.getSystemResource(className);
}

className is "name.class" and it's in the directory of "eclipse project file"; D is always "null"; I just see around web and it seems a popular problem but i don't still find the solution....

could you help me, please?

thanks,