You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AnyLogic访问Sedan代理queueEntryTime报错:无法静态引用非静态字段

解决方法

错误原因很明确:你用Sedan.queueEntryTime是通过类名访问非静态成员,而queueEntryTime是每个Sedan实例独有的属性,不属于类本身,Java不允许这种静态引用方式。

按以下步骤修改代码:

  1. 获取当前通过停止线的具体Sedan实例
    在停止线的触发代码中,用AnyLogic提供的getVehicle()方法拿到当前车辆,再强转为Sedan类型:

    Sedan currentSedan = (Sedan) getVehicle();
    
  2. 计算并统计等待时间
    通过获取到的实例访问queueEntryTime,完成计算和统计:

    double waitingTime = time() - currentSedan.queueEntryTime;
    vehicleWaitingTimeStats.add(waitingTime);
    
  3. 可选:兼容多车辆类型
    如果你的模型里还有其他类型车辆,加个类型判断避免强转报错:

    Vehicle vehicle = getVehicle();
    if (vehicle instanceof Sedan) {
        Sedan currentSedan = (Sedan) vehicle;
        double waitingTime = time() - currentSedan.queueEntryTime;
        vehicleWaitingTimeStats.add(waitingTime);
    }
    

额外提醒:确保queueEntryTime是在车辆进入队列时被正确赋值为time(),比如在车辆接近停止线的触发逻辑里设置,否则统计的等待时间会不准确。

内容的提问来源于stack exchange,提问作者Fair

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 22:42:37