GraphHopper.com | Forum | GitHub | Maps | Blog

ByteBuffer error on loading graph on Android


#1

I have custom build graph files that were built with core version 0.12.

In my MainActivity I want to load these files as following:

void loadGraphStorage() {
    logUser("loading graph (" + Constants.VERSION + ") ... ");
    new GHAsyncTask<Void, Void, Path>() {
        protected Path saveDoInBackground(Void... v)  {
            GraphHopper tmph = new GraphHopper().forMobile();
            tmph.load((mapsFolder.getAbsolutePath()));
            log("found graph " + hopper.getGraphHopperStorage().toString() + ", nodes:" + hopper.getGraphHopperStorage().getNodes());
            hopper = tmph;
            return null;
        }

        protected void onPostExecute(Path o) {
            if (hasError()) {
                logUser("An error happened while creating graph:"
                        + getErrorMessage());
            } else {
                logUser("Finished loading graph. Long press to define where to start and end the route.");
            }

            finishPrepare();
        }
    }.execute();
}

and I receive this log:

/com.graphhopper.android I/GH: An error happened while creating graph:No virtual method position(I)Ljava/nio/ByteBuffer; in class Ljava/nio/ByteBuffer; or its super classes (declaration of ‘java.nio.ByteBuffer’ appears in /system/framework/core-oj.jar

Prepare finished but hopper not ready. This happens when there was an error while loading the files

I read that these errors concerning ByteBuffer classes could occure upon a JDK incompatibility?

im running:

Android 8.1 API 27

and Android Studio

JAVA_VERSION=“1.8.0_152”
OS_NAME=“Darwin”
OS_VERSION=“11.2”
OS_ARCH=“x86_64”
SOURCE=""

can anybody help me out?


#2

I solved the issue with compiling the Snapshot dependency in Intelij Idea (with JDK 1.8.0.192) instead of eclipse (with JDK 1.8.0.192) . Though I can’t tell what really caused the issue.

Moreover my research brought to daylight that compiling with JDK 9 won’t work because of the missing sun.misc library. Also the java/nio/ByteBuffer class has been changed in JDK 9 so I can’t recommend using it.