No suitable method found for forEach error

Hi everyone,

On GH version 0.9, I am getting an error message from com/graphhopper/routing/AlternativeRoute.java, line 333, which says:

error: no suitable method found for forEach(<anonymous IntObjectPredicate<SPTEntry>>)

I know the recommended java version is Oracle’s JDK 9, however for various reasons I need to be on open-jdk-8 on Ubuntu, so I need to be able to compile the code on JDK 8. I also get a similar error from com/graphhopper/routing/lm/LandmarkStorage.java line 778 but these are the only two errors.

My question is how can I change these two code blocks to be compatible with Java 8?

Thanks in advance,

Java 9 isn’t released yet.

GraphHopper requires Java 8 (but it’s compatible with Android Java 7 requirements).

Are you sure your IDE is configured that way?

Hi, I created a bare-bones build environment with Ant (another tool I have to use), that has no Android dependencies for now, I have

<project name="gh" default="dist" basedir=".">
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="dist" location="dist"/>
  <echo>${java.home}</echo>  
  <target name="init">
    <tstamp/>
    <mkdir dir="${build}"/>
  </target>
  <path id="build.classpath">
    <fileset dir="lib">
      <include name="**/*.jar"/>
    </fileset>
  </path>  
  <target name="compile" depends="init"
        description="compile the source">
    <javac destdir="${build}" >
      <src path="${src}"/>
    <classpath refid="build.classpath"/>
  </javac>
  </target>
  <target name="dist" depends="compile" description="generate the distribution">
    <mkdir dir="${dist}/lib"/>
    <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
  </target>
  <target name="clean"
        description="clean up">
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
  </target>
</project>

Compilation tells me I have /usr/lib/jvm/java-8-openjdk-amd64/jre, which is right.

I took the jar files from maven repositories, and copied them under lib/. The list of jars,

hppc-0.3.4.jar
hppc-0.7.0.jar
jackson-annotations-2.8.8.jar
jackson-databind-2.8.8.jar
jts-core-1.14.0.jar
osmosis-osm-binary-0.43-RELEASE.jar
protobuf-java-3.3.1.jar
slf4j-api-1.7.21.jar
stax-api-1.0-2.jar
xmlgraphics-commons-1.4.jar

For Java sources, I copied all necessary GH java files related to routing, from core, reader-osm. This is pretty much all I have.

I realize the build approach is somewhat old school, nowadays w/ gradle and maven everything is downloaded, setup for you… unfortunately this is what I need to use :expressionless:

You can check GraphHopper core pom.xml for the dependencies.

Also as seen in root pom.xml can use source / target with 1.7 compatibility.
I think Ant javac task has such parameters too.

Do you run it in command line or within an IDE?
Eventually the easiest way is to open the project with a Maven capable IDE (all are). :slight_smile:

That was it. I had the wrong versions for some jars. Now it compiles. Thanks!