简体   繁体   English

ExportInfo 无法解析为类型

[英]ExportInfo cannot be resolved to a type

In my wait block in anylogic, I have written the following:在我的 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)));

Now, I want an event block to trigger writing values to Excel. So, in my event block I have written:现在,我想要一个事件块来触发将值写入 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();

However, this gives me the errors: ExportInfo cannot be resolved to a type & list cannot be resolved to a variable但是,这给了我错误:ExportInfo cannot be resolved to a type & list cannot be resolved to a variable

When I place this part of the code in the wait block, just as the first part, i do not get this error.当我将这部分代码放在等待块中时,就像第一部分一样,我没有收到此错误。 However, then only the info from 1 agent is written to my Excel, so it should be placed in the event block.然而,只有来自 1 个代理的信息被写入我的 Excel,所以它应该放在事件块中。 Does anyone know why I get these errors when I place it in event?有谁知道为什么我将它放在事件中时会出现这些错误? It seems like it cannot access ExportInfo and list, but I do not know how to fix that.它似乎无法访问 ExportInfo 和列表,但我不知道如何解决。

I have tried using我试过使用

public class ExportInfo {
        private int id;
        private int P;
        private double d;
    }

in the wait block, but then I get the error Illegal modifier for the local class ExportInfo;在等待块中,但随后我收到本地 class ExportInfo 的错误非法修饰符; only abstract or final is permitted只允许摘要或最终

You define the ExportInfo class within a Wait block, this means it only can exist inside that block.您在Wait块中定义ExportInfo class,这意味着它只能存在于该块内。 If you want to use it in an Event , that has no idea what you are talking about.如果您想在Event中使用它,那不知道您在说什么。

First, start using code-complete when writing code, you are only to write code that Java/AnyLogic would actually be able to understand.首先,在编写代码时开始使用代码完成,你只需要编写 Java/AnyLogic 实际上能够理解的代码。 ie in your event, it would not let you even write ExportInfo .即在您的活动中,它甚至不允许您编写ExportInfo

To solve this, you should move the class definition and constructor to the Agent that holds both the Wait block and the event.要解决此问题,您应该将 class 定义和构造函数移至同时包含 Wait 块和事件的 Agent。 Put the code into the "Additional class code" section of your agent properties:将代码放入代理属性的“附加 class 代码”部分: 在此处输入图像描述

Also, your original constructor is using the agent.此外,您的原始构造函数正在使用agent. keyword from the Wait-block code section, you cannot use that here.等待块代码部分中的关键字,您不能在此处使用它。 In your wait block, you can now create ExportInfo items using the constructor above, ie new ExportInfo(agent.atrID, agent.atrEstimatedPackingTime, dateToTime(agent.atrDueDate))在等待块中,您现在可以使用上面的构造函数创建ExportInfo项目,即new ExportInfo(agent.atrID, agent.atrEstimatedPackingTime, dateToTime(agent.atrDueDate))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM