簡體   English   中英

ExportInfo 無法解析為類型

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM