gpt4 book ai didi

java - createAgent() Jade 中的非法访问异常

转载 作者:行者123 更新时间:2023-12-01 19:38:24 25 4
gpt4 key购买 nike

当我尝试在我的简单程序中创建代理时出现异常。有我的代码: 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$1.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$1.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 没有其他字段,为什么我会遇到此异常。所有修饰符都是私有(private)的。修饰符“”是什么意思?我该如何修复它?程序的真实版本要大得多。上面的程序是通过注释大量代码得到的。

最佳答案

我建议您公开 DefaultAgent 的构造函数。

关于java - createAgent() Jade 中的非法访问异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59191830/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com