matsim-org/pt2matsim

NoSuchMethodError while running PTMapper

Closed this issue · 5 comments

Hello everyone,
I recently updated a project of mine to MATSim 12.0 and now changed the version of pt2matsim to 21.1. Since this update I am getting a "NoSuchMethodError" during the creation of link candidates while mapping the schedule to the network:

Exception in thread "main" java.lang.NoSuchMethodError: org.matsim.pt.transitSchedule.api.TransitRouteStop.getArrivalOffset()D
	at org.matsim.pt2matsim.mapping.linkCandidateCreation.PublicTransitStop.createId(PublicTransitStop.java:51)
	at org.matsim.pt2matsim.mapping.linkCandidateCreation.LinkCandidateCreatorStandard.load(LinkCandidateCreatorStandard.java:115)
	at org.matsim.pt2matsim.mapping.linkCandidateCreation.LinkCandidateCreatorStandard.<init>(LinkCandidateCreatorStandard.java:71)
	at org.matsim.pt2matsim.mapping.PTMapper.run(PTMapper.java:113)
	at org.matsim.pt2matsim.mapping.PTMapper.run(PTMapper.java:100)
	...

I am not completely sure whether the problem here lies in the code or if it is a dependecy problem. What I don't understand is, that the JVM searches for the "getArrivalOffset" method that returns a double and not the new "OptionalTime" object. It looks like it tries to call an outdated version of this method, since the method in MATSim 12.0 returns OptionalTime, but i don't know, where this is comming from. I already did a clean install with maven, but the error still occurs.

My pom.xml looks like this:

<repositories>
        <repository>
                <id>matsim</id>
                <url>https://dl.bintray.com/matsim/matsim</url>
        </repository>
      	
        <repository>
                <id>pt2matsim</id>
                <url>http://dl.bintray.com/polettif/matsim</url>
        </repository>
</repositories>

<dependencies>
        <dependency>
                <groupId>org.matsim</groupId>
                <artifactId>matsim</artifactId>
                <version>12.0</version>
        </dependency>
		
        <dependency>
                <groupId>org.matsim</groupId>
                <artifactId>pt2matsim</artifactId>
                <version>21.1</version>
        </dependency>
</dependencies>	

Any kind of input on how to solve this error would be greatly appreciated!

Looks like something in your project still points to the older version of MATSim. I don't really know how to fix this, have you cleaned and reinstalled the project with maven?

you could try running mvn dependency:tree in your project to see if there are other dependencies that still use an older version of MATSim.

Thanks for your advice!

I have cleaned and reinstalled the project and even set up a new eclipse workspace to be sure it is not some eclipse issue. However, I still recieve the error. When running mvn dependency:tree, none of the MATSim-related dependencies show any signs of MATSim 11 or older:

[INFO] +- org.matsim:matsim:jar:12.0:compile
[INFO] |  +- org.apache.logging.log4j:log4j-api:jar:2.13.0:compile
[INFO] |  +- org.apache.logging.log4j:log4j-core:jar:2.13.0:compile
[INFO] |  +- org.apache.logging.log4j:log4j-1.2-api:jar:2.13.0:compile
[INFO] |  +- org.jfree:jfreechart:jar:1.5.0:compile
[INFO] |  +- org.jfree:jcommon:jar:1.0.24:compile
[INFO] |  +- com.google.inject:guice:jar:4.2.2:compile
[INFO] |  |  +- javax.inject:javax.inject:jar:1:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- com.google.inject.extensions:guice-multibindings:jar:4.2.2:compile
[INFO] |  +- com.google.inject.extensions:guice-grapher:jar:4.2.2:compile
[INFO] |  |  \- com.google.inject.extensions:guice-assistedinject:jar:4.2.2:compile
[INFO] |  +- org.jgrapht:jgrapht-core:jar:1.4.0:compile
[INFO] |  |  \- org.jheaps:jheaps:jar:0.11:compile
[INFO] |  +- net.sf.trove4j:trove4j:jar:3.0.3:compile
[INFO] |  +- org.jvnet.ogc:kml-v_2_2_0:jar:2.2.0:compile
[INFO] |  |  +- org.hisrc.w3c:atom-v_1_0:jar:1.1.0:compile
[INFO] |  |  \- org.jvnet.jaxb2_commons:jaxb2-basics-runtime:jar:0.9.4:compile
[INFO] |  +- org.lz4:lz4-java:jar:1.7.1:compile
[INFO] |  +- com.github.luben:zstd-jni:jar:1.4.4-7:compile
[INFO] |  +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] |  +- org.hibernate.validator:hibernate-validator:jar:6.1.1.Final:compile
[INFO] |  |  +- jakarta.validation:jakarta.validation-api:jar:2.0.2:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] |  +- org.hibernate.validator:hibernate-validator-annotation-processor:jar:6.1.1.Final:compile
[INFO] |  +- org.glassfish:javax.el:jar:3.0.1-b11:compile
[INFO] |  +- org.apache.commons:commons-compress:jar:1.20:compile
[INFO] |  +- org.apache.commons:commons-csv:jar:1.8:compile
[INFO] |  +- javax.xml.bind:jaxb-api:jar:2.3.1:compile
[INFO] |  |  \- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] |  +- com.sun.xml.bind:jaxb-core:jar:2.3.0.1:compile
[INFO] |  +- com.sun.xml.bind:jaxb-impl:jar:2.3.0.1:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.10.2:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.10.2:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-core:jar:2.10.2:compile
[INFO] +- org.matsim:pt2matsim:jar:21.1:compile
[INFO] |  +- com.opencsv:opencsv:jar:3.7:compile
[INFO] |  +- commons-io:commons-io:jar:2.4:compile
[INFO] |  +- de.grundid.opendatalab:geojson-jackson:jar:1.5:compile
[INFO] |  \- net.lingala.zip4j:zip4j:jar:1.3.2:compile

My best guess would be, that either there is a deeper lying problem with my maven installation or the method call in pt2matsim is somehow faulty. Are you sure the latter is not the case?

I don't know how your project is set up but you don't really need a dependency on MATSim 12 if you already have a dependency on ptmasim.

or the method call in pt2matsim is somehow faulty. Are you sure the latter is not the case?

Well, not beyond any doubt but the latest CI build and tests run successfully and I can compile and run it on my own machine.

Today I tested following your advide and removed the MATSim 12 dependency from my projects pom.xml. But the same error still occured.

I managed to fix the issue now, by excluding the matsim artifact from the pt2matsim dependency. My pom.xml now looks like this:

<repositories>
        <repository>
                <id>matsim</id>
                <url>https://dl.bintray.com/matsim/matsim</url>
        </repository>
      	
        <repository>
                <id>pt2matsim</id>
                <url>http://dl.bintray.com/polettif/matsim</url>
        </repository>
</repositories>

<dependencies>
        <dependency>
                <groupId>org.matsim</groupId>
                <artifactId>matsim</artifactId>
                <version>12.0</version>
        </dependency>
		
	<dependency>
	        <groupId>org.matsim</groupId>
	        <artifactId>pt2matsim</artifactId>
	        <version>21.1</version>
			<exclusions>
				<exclusion>
					<artifactId>matsim</artifactId>
					<groupId>org.matsim</groupId>
				</exclusion>
			</exclusions>
    	</dependency>	
</dependencies>	

I still don't really understand what the problem is, since pt2matsim should theoretically import the same matsim version as I did. Maybe this is an issue which is unique to my installation, but if anyone has the same problem in the future, hopefully this can be of help.