matsim-org / matsim-code-examples

A repository containing code examples around MATSim
GNU General Public License v3.0
83 stars 179 forks source link

Error while running code in MATSim #1069

Open Jayzijun opened 9 months ago

Jayzijun commented 9 months ago

Hello, I am a beginner in MATSim and I have tried out the matsim-example-project and it works perfectly fine. However when trying to run a different scenario, I have encountered a long string of errors which I am not sure how to solve. I also do not know much about Java so there would be a need for guidance in this part too.

Here are the warnings & errors:

2024-01-09 12:43:31,791  WARN PlanCalcScoreConfigGroup$ReflectiveDelegate:1558 Setting pathSizeLogitBeta different from zero is experimental.  KN, Sep’08

Exception in thread “main” java.lang.ExceptionInInitializerError
    at com.google.inject.internal.cglib.reflect.$FastClass$Generator.getProtectionDomain
(FastClass.java:73)
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create
(AbstractClassGenerator.java:206)
    at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create
(FastClass.java:65)
    at com.google.inject.internal.BytecodeGen.newFastClassForMember
(BytecodeGen.java:252)
    at com.google.inject.internal.BytecodeGen.newFastClassForMember
(BytecodeGen.java:203)
    at com.google.inject.internal.ProviderMethod.create
(ProviderMethod.java:69)
    at com.google.inject.internal.ProviderMethodsModule.createProviderMethod
(ProviderMethodsModule.java:275)
    at com.google.inject.internal.ProviderMethodsModule.getProviderMethods
(ProviderMethodsModule.java:144)
    at com.google.inject.internal.ProviderMethodsModule.configure
(ProviderMethodsModule.java:123)
    at com.google.inject.spi.Elements$RecordingBinder.install
(Elements.java:340)
    at com.google.inject.spi.Elements$RecordingBinder.install
(Elements.java:349)
    at org.matsim.core.controler.AbstractModule.install
(AbstractModule.java:129)
    at org.matsim.core.mobsim.qsim.QSimModule.install
(QSimModule.java:46)
    at org.matsim.core.controler.AbstractModule.configure
(AbstractModule.java:118)
    at com.google.inject.spi.Elements$RecordingBinder.install
(Elements.java:340)
    at org.matsim.core.controler.AbstractModule.install
(AbstractModule.java:129)
    at org.matsim.core.mobsim.DefaultMobsimModule.install
(DefaultMobsimModule.java:36)
    at org.matsim.core.controler.AbstractModule.configure
(AbstractModule.java:118)
    at com.google.inject.spi.Elements$RecordingBinder.install
(Elements.java:340)
    at org.matsim.core.controler.AbstractModule.install
(AbstractModule.java:129)

at org.matsim.core.controler.ControlerDefaultsModule.install
(ControlerDefaultsModule.java:43)
    at org.matsim.core.controler.AbstractModule.configure
(AbstractModule.java:118)
    at com.google.inject.spi.Elements$RecordingBinder.install
(Elements.java:340)
    at org.matsim.core.controler.AbstractModule.install
(AbstractModule.java:129)
    at org.matsim.core.controler.Controler$2.install
(Controler.java:229)
    at org.matsim.core.controler.AbstractModule.configure
(AbstractModule.java:118)
    at com.google.inject.spi.Elements$RecordingBinder.install
(Elements.java:340)
    at com.google.inject.spi.Elements.getElements
(Elements.java:110)
    at com.google.inject.util.Modules$OverrideModule.configure
(Modules.java:177)
    at com.google.inject.AbstractModule.configure
(AbstractModule.java:62)
    at com.google.inject.spi.Elements$RecordingBinder.install
(Elements.java:340)
    at org.matsim.core.controler.AbstractModule$4.install
(AbstractModule.java:250)
    at org.matsim.core.controler.AbstractModule.configure
(AbstractModule.java:118)
    at com.google.inject.spi.Elements$RecordingBinder.install
(Elements.java:340)
    at com.google.inject.spi.Elements.getElements
(Elements.java:110)
    at com.google.inject.spi.Elements.getElements
(Elements.java:101)
    at org.matsim.core.controler.Injector.createMapBindingsForType
(Injector.java:111)
    at org.matsim.core.controler.Injector.insertMapBindings
(Injector.java:103)
    at org.matsim.core.controler.Injector.createInjector
(Injector.java:74)
    at org.matsim.core.controler.Controler.run
(Controler.java:223)
    at org.matsim.run.Controler.run
(Controler.java:56)
    at org.matsim.run.Controler.main
(Controler.java:60)

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineclass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not “opens java.lang” to unnamed module @34252efb

    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible
(AccessibleObject.java:354)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible
(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Method.checkCanSetAccessible
(Method.java:199)
    at java.base/java.lang.reflect.Method.setAccessible
(Method.java:193)
    at com.google.inject.internal.cglib.core.$ReflectUtils$1.run
(ReflectUtils.java:52)
    at java.base/java.security.AccessController.doPrivileged
(AccessController.java:318)
    at com.google.inject.internal.cglib.core.$ReflectUtils.<clinit>
(ReflectUtils.java:42)
    …42 more

The simulation did not run properly. Error/Exit code: 1

Open to suggestions and assistances. Thanks.

mrieser commented 9 months ago

Unable to make protected final java.lang.Class java.lang.ClassLoader.defineclass

What version of MATSim are you using? What Java version are you using?

I think we had similar error messages with older versions of MATSim on very new Java versions. I think the latest MATSim version should work well with Java 17, so maybe give that combination a try.

Jayzijun commented 9 months ago

Hi @mrieser,

my current Java version is 17.0.7; Private Build; mixed mode, sharing; 64-bit and my MATSim version is Build: ra5d8c2fe629e3d2a2302c2276f7ea6cdc631c641 (2023-02-08 21:47:36)

I would think that the problem would come from the code since I was able to run the example simulation. However, now that you have brought up the topic of software versions, could it be that my current version of my MATSim is unable to work with Java 17?

mrieser commented 9 months ago

Java 17 should actually be okay. In the past, we had issues with very new java versions, but that should not be the case here.

 Caused by: java.lang.reflect.InaccessibleObjectException: 
Unable to make protected final java.lang.Class java.lang.ClassLoader.defineclass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
 throws java.lang.ClassFormatError accessible: module java.base does not “opens java.lang” to unnamed module @34252efb

The error message states something about modules.

How do you start MATSim? What command do you exactly use?

Searching for the above error message suggests adding --add-opens=java.base/java.lang=ALL-UNNAMED when starting MATSim, e.g. something like this:

java -Xmx4g --add-opens=java.base/java.lang=ALL-UNNAMED -jar matsim.jar org.matsim.run.Controler myConfig.xml
Jayzijun commented 9 months ago

Hi @mrieser,

When I start MATSim, I use the command java -jar matsim-spatialDRT_noav_gradual.jar

I have also tried the method that you have provided but it still has the same errors. Perhaps I did not key it in correctly?

The format that i used was java -Xmx4g --add-opens=java.base/java.lang=ALL-UNNAMED -jar matsim-spatialDRT_noav_gradual.jar org.matsim.run.Controler defaultConfig.xml