AnyLogic多运行实验打开检查窗口触发ClassCastException求助
Environment Details
- AnyLogic 8 Personal Learning Edition 8.9.6 (Build: 8.9.6.202509050523 x64)
- Java Version: 1.8.0_461
- Java(TM) SE Runtime Environment (build 1.8.0_461-b11)
- Java HotSpot(TM) 64-Bit Server VM (build 25.461-b11, mixed mode)
Problem Description
I built a simple DES model with patient agents. The Simulation Experiment runs normally, and all model modules' inspect windows open without issues. However, in Parameter Variation or Monte Carlo Experiments, trying to open inspect windows for double-type collections, datasets, or similar model elements throws a ClassCastException.
Troubleshooting Steps Already Attempted
- Tested with my own previously functional models: same error occurs
- Tested with AnyLogic official sample models: same error occurs
- Replicated the issue on both work and personal computers
- Reinstalled AnyLogic entirely
- Restarted multiple times
- Added the Java argument
--add-opens java.base/java.lang=ALL-UNNAMEDin the experiment's Advanced Java tab
Relevant Code
In the After simulation run Java action of the Parameter Variation experiment:
collection.add(root.LOS.mean()); dataset.add(getCurrentIteration(), route1_Prob);
route1_Prob increments from 0.00 to 1.00 in 0.1 steps, with 10 repetitions per iteration, using Random seed mode for random number generation.
Practical Fixes & Workarounds
Downgrade Java 8 Version
AnyLogic 8.9.x has compatibility quirks with very recent Java 8 updates. Try rolling back to an older release like Java 8 Update 292 or 333. Update AnyLogic's Java path in File > Preferences > Java to point to this older JRE, then restart the software.Skip Inspection During Batch Runs
Instead of opening inspect windows mid-experiment, export your collection/dataset data to a CSV file for post-analysis. Add this code to the experiment's finalization action:writeToCSVFile("collection_results.csv", collection); writeToCSVFile("dataset_results.csv", dataset);You can then open these files in Excel or a spreadsheet tool to review the data.
Check Variable Scope & Initialization
Ensure your collection/dataset variables are initialized at the experiment level (not just the model root) and set to persist across iterations. Misconfigured variable scope can cause unexpected casting errors when accessing data in batch experiments.Report to AnyLogic Support
Since this issue occurs across multiple models, machines, and after reinstallation, it’s likely a bug in version 8.9.6. Submit a bug report with your environment details, error stack trace, and code snippet—AnyLogic’s support team may provide a hotfix or confirm if this is resolved in a newer release.
内容的提问来源于stack exchange,提问作者Joe Viana

