You are not logged in.
Pages: 1
I was wondering if there was a way to launch an inner class from the outer class. For example
class outerClass
{
main()
{
///code
new Madkit("--launchAgents", innerClass.class.getName() +",true;" + ConsoleAgent.class.getName());
}
class innerClass extends scheduler
{
activate()
{
//code
}
}
}
This gives me an InstantiationError, i guess because it cant find the correct class name?
Last edited by oxality (2016-03-08 19:26:11)
Offline
This gives me an InstantiationError, i guess because it cant find the correct class name?
Not exactly. In fact, to instantiate an inner class you need to do it from an existing instance of the enclosing class, i.e. outerClass here, which cannot be the case when you only pass the name of the inner class to the kernel.
So, for doing this you can use the following :
public class InnerAgentClassTest {
public static void main(String[] args) {
InnerAgentClassTest test = new InnerAgentClassTest();
Madkit m = new Madkit("--launchAgents", ConsoleAgent.class.getName());
m.doAction(KernelAction.LAUNCH_AGENT, test.new InnerClass(),Boolean.TRUE);
}
class InnerClass extends Scheduler
{
@Override
protected void activate() {
super.activate();
}
}
}
Offline
ah ok. is there a way to pass values to the new Agent when you launch it, similar to the way you can pass values when constructing an object? Ive noticed AbstractAgents ignore/dont require constructors
Offline
ah ok. is there a way to pass values to the new Agent when you launch it, similar to the way you can pass values when constructing an object? Ive noticed AbstractAgents ignore/dont require constructors
AbstractAgents subclasses can have their own constructor and thus be parametrized when instantiated before being launched using the launchAgent(madkit.kernel.AbstractAgent) version. Is it what you are looking for or do you have another use case in mind ?
Offline
This worked, thanks. However now the panel for that AbstractAgent doesnt pop up. Any output set through logger just goes to my IDE terminal. Im just using the inherited setupFrame method if that matters
Offline
This worked, thanks. However now the panel for that AbstractAgent doesnt pop up. Any output set through logger just goes to my IDE terminal. Im just using the inherited setupFrame method if that matters
Well, it should just be because you have to use the version of the method that includes the boolean parameter so that the agent has a GUI or not, i.e. launchAgent(a,true). Does this solve your problem ?
Offline
That did it. Thank you
Offline
Pages: 1