计算数据表中的元素

counting the elements in datatable

enter image description here enter image description here enter image description here

我一直在尝试计算数据中元素的数量 table,但是出现了一些错误,错误显示“无法将 long 转换为 int”。我正在将它定义为参数。有人可以帮我吗?我更改了数据的名称 table 并使用了下面提到的两种代码,但运气不佳

代码:

1)selectFrom(comp) .groupBy(comp.components) .uniqueResult(comp.components.count());```

2)selectFrom(comp) .groupBy(comp.components.count());

错误:“类型不匹配:无法从 long 转换为 int”

数据Table:名称是“comp”,列“Components”有组件的名称(字符串)

这实际上工作正常,只是用 this example model 重新测试了你。

所以 2 个选项:

  1. 您使用的是旧版本的 AnyLogic 或一些旧的 Java 或一些 OS 特定的奇怪东西(不太可能)
  2. 您正在加载“不干净”的数据。您可能从一个 Excel 文件加载,该文件在您加载的单元格后面有一些公式。始终确保加载 100%“干净”的数据,即纯数据,没有公式。

检查我的示例模型是否适用于您的机器,如果适用:解决 #2,即修复您的数据