[英]Syntax error on token "start" , identifier expected after this token
I've been trying to create an agent thanks to jade on java with this code :由于 jade on java,我一直在尝试使用以下代码创建代理:
import jade.core.ProfileImpl;
import jade.wrapper.AgentContainer;
import jade.wrapper.AgentController;
public class Agents {
jade.core.Runtime rt= jade.core.Runtime.instance();
ProfileImpl pMain= new ProfileImpl();
AgentContainer mc = rt.createMainContainer(pMain);
AgentController rma= mc.createNewAgent("rma", "jade.tools.rma.rma", null);
rma.start();
}
but i keep getting the error message of the title and I cannot understand why.但我不断收到标题的错误消息,我不明白为什么。 Thanks for your help !
谢谢你的帮助 !
By not going into finding problems with your code, I suggest to use the code below to solve your error.通过不去寻找您的代码问题,我建议使用下面的代码来解决您的错误。
Initialization code for agent and adding to the container代理的初始化代码并添加到容器中
package package.se.samplejade;
import jade.wrapper.AgentController;
import jade.wrapper.StaleProxyException;
public class LaunchAgents {
private static final String AGENT_CLASS_STRING ="package.se.samplejade.SampleAgent";
private static final String AGENTNAME_STRING = "sampleAgent";
public static void main(String[] args) {
LaunchAgents LaunchAgents = new LaunchAgents();
LaunchAgents.initilizeAgent();
}
/**
* Creates a new agent and adds it to the container
*
* @param
* @return true or false
*/
public boolean initilizeAgent() {
AgentController agentcontroller = null;
Object[] initObjects = new Object[2];
initObjects[0] = new Object(); // add any object needed to initialize the agent
initObjects[1] = new Object();
try {
agentcontroller = Container.getController().createNewAgent(AGENTNAME_STRING, AGENT_CLASS_STRING,
initObjects);
agentcontroller.start();
return true;
} catch (StaleProxyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
}
The JADE container initialization JADE 容器初始化
package.se.samplejade ;
import jade.core.Profile;
import jade.core.ProfileImpl;
import jade.wrapper.ContainerController;
public final class Container {
// get a JADE runtime
private static jade.core.Runtime runtime = jade.core.Runtime.instance();
// Create a profile, where the launch arguments are stored
private static Profile profile2 = new ProfileImpl();
private static Profile profile = new ProfileImpl();
// create the Main-container
private static ContainerController mainContainer = null;
private static ContainerController containerController = null;
/**
* Returns the path of the container to the JADE agents
*/
public synchronized static ContainerController getController() {
// create the Main-container
if (mainContainer == null) {
profile.setParameter(Profile.CONTAINER_NAME, "Container");
profile.setParameter(Profile.GUI, "true");
mainContainer = runtime.createMainContainer(profile2);
containerController = runtime.createAgentContainer(profile);
}
return containerController;
}
}
The agents code代理代码
package.se.samplejade;
import jade.core.Agent;
public class SampleAgent extends Agent {
@Override
protected void setup() {
//Put your agent initialization code with the objects passed in the initialization
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.