createAgent() Jade 中的非法访问异常
Illegal access exception in createAgent() Jade
当我尝试在我的简单程序中创建代理时出现异常。
有我的代码:
DefaultAgent.java:
package ru.spbu.mas;
import jade.core.Agent;
import jade.core.behaviours.TickerBehaviour;
import java.util.concurrent.TimeUnit;
public class DefaultAgent extends Agent {
DefaultAgent() {
super();
}
@Override
protected void setup() {
int id = Integer.parseInt(getAID().getLocalName());
System.out.println("Agent #" + id);
addBehaviour(new TickerBehaviour(this, TimeUnit.SECONDS.toMillis(1)) {
@Override
protected void onTick() {
stop();
}
});
}
}
MainController.java(我隐藏了一些导入。认为问题不在其中):
class MainController {
private static final int numberOfAgents = 5;
private AgentController[] agents = new AgentController[numberOfAgents];
private int steps = 10;
void initAgents() {
Runtime rt = Runtime.instance();
Profile p = new ProfileImpl();
p.setParameter(Profile.MAIN_HOST, "localhost");
p.setParameter(Profile.MAIN_PORT, "10098");
p.setParameter(Profile.GUI, "true");
ContainerController cc = rt.createMainContainer(p);
try {
for(int i = 1; i <= MainController.numberOfAgents; i++) {
//Exception in that string of code
AgentController agent = cc.createNewAgent(Integer.toString(i), "ru.spbu.mas.DefaultAgent", null);
agents[i - 1] = agent;
}
} catch (Exception e) {
e.printStackTrace();
}
}
void startAgents() {
try {
for(int i = 1; i <= MainController.numberOfAgents; i++) {
agents[i].start();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
这是我的项目层次结构:
project hierarchy
这是我的 Gradle 依赖项:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation files('C:\Users\chote\Desktop\JADE-bin-4.5.0\jade\lib\jade.jar')
compileOnly 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
}
此处App.java:
package ru.spbu.mas;
public class App {
public static void main(String[] args) {
MainController mc = new MainController();
mc.initAgents();
mc.startAgents();
}
}
此处异常回溯:
jade.core.IMTPException: Illegal access exception in createAgent() - Caused by: Class jade.core.management.AgentManagementService$CommandTargetSink can not access a member of class ru.spbu.mas.DefaultAgent with modifiers ""
at jade.core.management.AgentManagementService$CommandTargetSink.createAgent(AgentManagementService.java:630)
at jade.core.management.AgentManagementService$CommandTargetSink.handleRequestCreate(AgentManagementService.java:533)
at jade.core.management.AgentManagementService$CommandTargetSink.consume(AgentManagementService.java:488)
at jade.core.CommandProcessor$SinksFilter.accept(CommandProcessor.java:253)
at jade.core.Filter.filter(Filter.java:89)
at jade.core.Filter.filter(Filter.java:90)
at jade.core.Filter.filter(Filter.java:90)
at jade.core.CommandProcessor.processIncoming(CommandProcessor.java:229)
at jade.core.BaseNode.serveVerticalCommand(BaseNode.java:163)
at jade.core.BaseNode.serveHorizontalCommand(BaseNode.java:111)
at jade.imtp.leap.NodeLEAP.accept(NodeLEAP.java:60)
at jade.core.management.AgentManagementProxy.createAgent(AgentManagementProxy.java:67)
at jade.core.AgentContainerImpl.createAgent(AgentContainerImpl.java:176)
at jade.wrapper.ContainerController.createNewAgent(ContainerController.java:135)
at ru.spbu.mas.MainController.initAgents(MainController.java:36)
at ru.spbu.mas.App.main(App.java:6)
Nested Exception:
java.lang.IllegalAccessException: Class jade.core.management.AgentManagementService$CommandTargetSink can not access a member of class ru.spbu.mas.DefaultAgent with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
at java.lang.Class.newInstance(Class.java:436)
at jade.core.management.AgentManagementService$CommandTargetSink.createAgent(AgentManagementService.java:612)
at jade.core.management.AgentManagementService$CommandTargetSink.handleRequestCreate(AgentManagementService.java:533)
at jade.core.management.AgentManagementService$CommandTargetSink.consume(AgentManagementService.java:488)
at jade.core.CommandProcessor$SinksFilter.accept(CommandProcessor.java:253)
at jade.core.Filter.filter(Filter.java:89)
at jade.core.Filter.filter(Filter.java:90)
at jade.core.Filter.filter(Filter.java:90)
at jade.core.CommandProcessor.processIncoming(CommandProcessor.java:229)
at jade.core.BaseNode.serveVerticalCommand(BaseNode.java:163)
at jade.core.BaseNode.serveHorizontalCommand(BaseNode.java:111)
at jade.imtp.leap.NodeLEAP.accept(NodeLEAP.java:60)
at jade.core.management.AgentManagementProxy.createAgent(AgentManagementProxy.java:67)
at jade.core.AgentContainerImpl.createAgent(AgentContainerImpl.java:176)
at jade.wrapper.ContainerController.createNewAgent(ContainerController.java:135)
at ru.spbu.mas.MainController.initAgents(MainController.java:36)
at ru.spbu.mas.App.main(App.java:6)
jade.wrapper.StaleProxyException: Illegal access exception in createAgent() - Caused by: Class jade.core.management.AgentManagementService$CommandTargetSink can not access a member of class ru.spbu.mas.DefaultAgent with modifiers ""
at jade.wrapper.ContainerController.createNewAgent(ContainerController.java:140)
at ru.spbu.mas.MainController.initAgents(MainController.java:36)
at ru.spbu.mas.App.main(App.java:6)
java.lang.NullPointerException
at ru.spbu.mas.MainController.startAgents(MainController.java:47)
at ru.spbu.mas.App.main(App.java:7)
如果 DefaultAgent 没有附加字段,为什么我会得到这个异常。所有修饰符都是私有的。修饰符“”是什么意思?我该如何解决?程序的真实版本要大得多。上面的程序注释了一大段代码。
我建议您创建 DefaultAgent 的构造函数 public。
当我尝试在我的简单程序中创建代理时出现异常。 有我的代码: DefaultAgent.java:
package ru.spbu.mas;
import jade.core.Agent;
import jade.core.behaviours.TickerBehaviour;
import java.util.concurrent.TimeUnit;
public class DefaultAgent extends Agent {
DefaultAgent() {
super();
}
@Override
protected void setup() {
int id = Integer.parseInt(getAID().getLocalName());
System.out.println("Agent #" + id);
addBehaviour(new TickerBehaviour(this, TimeUnit.SECONDS.toMillis(1)) {
@Override
protected void onTick() {
stop();
}
});
}
}
MainController.java(我隐藏了一些导入。认为问题不在其中):
class MainController {
private static final int numberOfAgents = 5;
private AgentController[] agents = new AgentController[numberOfAgents];
private int steps = 10;
void initAgents() {
Runtime rt = Runtime.instance();
Profile p = new ProfileImpl();
p.setParameter(Profile.MAIN_HOST, "localhost");
p.setParameter(Profile.MAIN_PORT, "10098");
p.setParameter(Profile.GUI, "true");
ContainerController cc = rt.createMainContainer(p);
try {
for(int i = 1; i <= MainController.numberOfAgents; i++) {
//Exception in that string of code
AgentController agent = cc.createNewAgent(Integer.toString(i), "ru.spbu.mas.DefaultAgent", null);
agents[i - 1] = agent;
}
} catch (Exception e) {
e.printStackTrace();
}
}
void startAgents() {
try {
for(int i = 1; i <= MainController.numberOfAgents; i++) {
agents[i].start();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
这是我的项目层次结构: project hierarchy
这是我的 Gradle 依赖项:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation files('C:\Users\chote\Desktop\JADE-bin-4.5.0\jade\lib\jade.jar')
compileOnly 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
}
此处App.java:
package ru.spbu.mas;
public class App {
public static void main(String[] args) {
MainController mc = new MainController();
mc.initAgents();
mc.startAgents();
}
}
此处异常回溯:
jade.core.IMTPException: Illegal access exception in createAgent() - Caused by: Class jade.core.management.AgentManagementService$CommandTargetSink can not access a member of class ru.spbu.mas.DefaultAgent with modifiers ""
at jade.core.management.AgentManagementService$CommandTargetSink.createAgent(AgentManagementService.java:630)
at jade.core.management.AgentManagementService$CommandTargetSink.handleRequestCreate(AgentManagementService.java:533)
at jade.core.management.AgentManagementService$CommandTargetSink.consume(AgentManagementService.java:488)
at jade.core.CommandProcessor$SinksFilter.accept(CommandProcessor.java:253)
at jade.core.Filter.filter(Filter.java:89)
at jade.core.Filter.filter(Filter.java:90)
at jade.core.Filter.filter(Filter.java:90)
at jade.core.CommandProcessor.processIncoming(CommandProcessor.java:229)
at jade.core.BaseNode.serveVerticalCommand(BaseNode.java:163)
at jade.core.BaseNode.serveHorizontalCommand(BaseNode.java:111)
at jade.imtp.leap.NodeLEAP.accept(NodeLEAP.java:60)
at jade.core.management.AgentManagementProxy.createAgent(AgentManagementProxy.java:67)
at jade.core.AgentContainerImpl.createAgent(AgentContainerImpl.java:176)
at jade.wrapper.ContainerController.createNewAgent(ContainerController.java:135)
at ru.spbu.mas.MainController.initAgents(MainController.java:36)
at ru.spbu.mas.App.main(App.java:6)
Nested Exception:
java.lang.IllegalAccessException: Class jade.core.management.AgentManagementService$CommandTargetSink can not access a member of class ru.spbu.mas.DefaultAgent with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
at java.lang.Class.newInstance(Class.java:436)
at jade.core.management.AgentManagementService$CommandTargetSink.createAgent(AgentManagementService.java:612)
at jade.core.management.AgentManagementService$CommandTargetSink.handleRequestCreate(AgentManagementService.java:533)
at jade.core.management.AgentManagementService$CommandTargetSink.consume(AgentManagementService.java:488)
at jade.core.CommandProcessor$SinksFilter.accept(CommandProcessor.java:253)
at jade.core.Filter.filter(Filter.java:89)
at jade.core.Filter.filter(Filter.java:90)
at jade.core.Filter.filter(Filter.java:90)
at jade.core.CommandProcessor.processIncoming(CommandProcessor.java:229)
at jade.core.BaseNode.serveVerticalCommand(BaseNode.java:163)
at jade.core.BaseNode.serveHorizontalCommand(BaseNode.java:111)
at jade.imtp.leap.NodeLEAP.accept(NodeLEAP.java:60)
at jade.core.management.AgentManagementProxy.createAgent(AgentManagementProxy.java:67)
at jade.core.AgentContainerImpl.createAgent(AgentContainerImpl.java:176)
at jade.wrapper.ContainerController.createNewAgent(ContainerController.java:135)
at ru.spbu.mas.MainController.initAgents(MainController.java:36)
at ru.spbu.mas.App.main(App.java:6)
jade.wrapper.StaleProxyException: Illegal access exception in createAgent() - Caused by: Class jade.core.management.AgentManagementService$CommandTargetSink can not access a member of class ru.spbu.mas.DefaultAgent with modifiers ""
at jade.wrapper.ContainerController.createNewAgent(ContainerController.java:140)
at ru.spbu.mas.MainController.initAgents(MainController.java:36)
at ru.spbu.mas.App.main(App.java:6)
java.lang.NullPointerException
at ru.spbu.mas.MainController.startAgents(MainController.java:47)
at ru.spbu.mas.App.main(App.java:7)
如果 DefaultAgent 没有附加字段,为什么我会得到这个异常。所有修饰符都是私有的。修饰符“”是什么意思?我该如何解决?程序的真实版本要大得多。上面的程序注释了一大段代码。
我建议您创建 DefaultAgent 的构造函数 public。