[英]ExportInfo cannot be resolved to a type
在我的 anylogic 等待块中,我写了以下内容:
class ExportInfo {
private int id;
private int P;
private double d;
public ExportInfo(int id, int P, double d) {
this.id=agent.atrID;
this.P=agent.atrEstimatedPackingTime;
this.d=dateToTime(agent.atrDueDate);
}
}
LinkedList<ExportInfo> list = new LinkedList();
list.add(new ExportInfo(agent.atrID, agent.atrEstimatedPackingTime, dateToTime(agent.atrDueDate)));
现在,我想要一个事件块来触发将值写入 Excel。因此,在我的事件块中,我写了:
int row = 1;
for(ExportInfo e : list){
ALtoGA.setCellValue(e.id,1,row,1);
ALtoGA.setCellValue(e.P,1,row,2);
ALtoGA.setCellValue(e.d,1,row,3);
row++;
}
ALtoGA.writeFile();
但是,这给了我错误:ExportInfo cannot be resolved to a type & list cannot be resolved to a variable
当我将这部分代码放在等待块中时,就像第一部分一样,我没有收到此错误。 然而,只有来自 1 个代理的信息被写入我的 Excel,所以它应该放在事件块中。 有谁知道为什么我将它放在事件中时会出现这些错误? 它似乎无法访问 ExportInfo 和列表,但我不知道如何解决。
我试过使用
public class ExportInfo {
private int id;
private int P;
private double d;
}
在等待块中,但随后我收到本地 class ExportInfo 的错误非法修饰符; 只允许摘要或最终
您在Wait
块中定义ExportInfo
class,这意味着它只能存在于该块内。 如果您想在Event
中使用它,那不知道您在说什么。
首先,在编写代码时开始使用代码完成,你只需要编写 Java/AnyLogic 实际上能够理解的代码。 即在您的活动中,它甚至不允许您编写ExportInfo
。
要解决此问题,您应该将 class 定义和构造函数移至同时包含 Wait 块和事件的 Agent。 将代码放入代理属性的“附加 class 代码”部分:
此外,您的原始构造函数正在使用agent.
等待块代码部分中的关键字,您不能在此处使用它。 在等待块中,您现在可以使用上面的构造函数创建ExportInfo
项目,即new ExportInfo(agent.atrID, agent.atrEstimatedPackingTime, dateToTime(agent.atrDueDate))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.