> Hi sir...
> I am working(more properly studying) on the server side of a
[quoted text clipped - 6 lines]
> Now I "think" I should use reflection to start theclass....but I don't
> know how....I'm not very fond reflection!!
> > Hi sir...
> > I am working(more properly studying) on the server side of a
[quoted text clipped - 29 lines]
> Mark Jeffcoat
> Austin, TX
Ok , So 've tried in many ways (forname,getinstance...) but I can't
create an instance and run this very simple thread class...
Now I'll post my code...
Server class :
//is very simple...
AgentClassLoader loader = new AgentClassLoader();//creates instance
of my redefinied classloader
//Load the main class through agentclassloader
Class class=loader.loadClass(AGENT_NAME,FILE_PATH,false);
//I won't post my classloader code because it works correctly
System.out.println("Now Launching Agent..");
try {
class = Class.forName("app.MyTestAgent", true,loader);//I tryied
these methods..for name and new instance....but without success
//Note : "app" is the package and MyTestAgent is the class I want to
instanciate
class.newInstance();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
2nd Class : "MyTestAgent" extend Thread and is veeery simple!!
public class MyTestAgent extends Thread {
Platform platform;//this is a simple collector class with only simple
data inside
public MyTestAgent (Platform platform) {
this.platform = platform;
}
public void run(){//I have to run this method!!
//I won't post this code because is very simple
(retrieves parameters from plaform object)
}
Anybody knows how to do it??
Please Help Me!!
Thanks a lot guys ... bye..
Mark Jeffcoat - 28 Feb 2007 14:56 GMT
> Class class=loader.loadClass(AGENT_NAME,FILE_PATH,false);
>
[quoted text clipped - 9 lines]
>
> class.newInstance();
You know you have to do both, right? forName and newInstance.
class = Class.forName("app.MyTestAgent");
MyTestAgent = (MyTestAgent) class.newInstance();
> } catch (Exception e) {
> e.printStackTrace();
> System.exit(1);
> }
If you're getting an exception here, you should,
you know, read it. If the problem is that you don't
understand the exception, and you want an explanation,
you'll have to post the actual text.
Can you write a similar program that uses the default
classloader, and works? Make sure you can do that first,
then try with your own classloader. If you can't, you'll
at least have a simpler problem to solve.

Signature
Mark Jeffcoat
Austin, TX
Thomas Fritsch - 28 Feb 2007 16:00 GMT
> Ok , So 've tried in many ways (forname,getinstance...) but I can't
> create an instance and run this very simple thread class...
> Now I'll post my code...
[...]
> Class class=loader.loadClass(AGENT_NAME,FILE_PATH,false);
You can't use "class" as your variable name, because "class" is already a
key-word of the Java language. Use "c" or something else.

Signature
Thomas