简体   繁体   中英

ExportInfo cannot be resolved to a type

In my wait block in anylogic, I have written the following:

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:

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

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. 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.

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; only abstract or final is permitted

You define the ExportInfo class within a Wait block, this means it only can exist inside that block. If you want to use it in an Event , that has no idea what you are talking about.

First, start using code-complete when writing code, you are only to write code that Java/AnyLogic would actually be able to understand. ie in your event, it would not let you even write ExportInfo .

To solve this, you should move the class definition and constructor to the Agent that holds both the Wait block and the event. Put the code into the "Additional class code" section of your agent properties: 在此处输入图像描述

Also, your original constructor is using the 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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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