GraphHopper.com | Forum | GitHub | Maps | Blog

Graphopper Android read lock failed


#1

Hey, i would use graphhopper to draw route between two points, but i can’t load graphs ma code sample:

void loadGraphStorage() {
        protected Path saveDoInBackground(Void... v) throws Exception {
            GraphHopper tmpHopp = new GraphHopper().forMobile();
            String folderpath = new File("/storage/sdcard1/", currentArea).getAbsolutePath() + "-gh";
            File folder = new File(folderpath);
            if(folder.isDirectory() && folder.exists() && folder.canRead() && folder.canWrite()) {
                tmpHopp.load(folderpath);
                log("found graph " + tmpHopp.getGraphHopperStorage().toString() + ", nodes:" + tmpHopp.getGraphHopperStorage().getNodes());
                hopper = tmpHopp;
            }else{
                logUser("No access to folder");
            }
            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.");
            }

I have my map and graph files on sdcard. I read map file properly but when i try to load graphs on line tmpHopp.load(folderpath); i occure an error:
An error happened while creating graph: To avoid reading partial data we need to obtain the read lock but it failed. In /storage/sdcard1/poland-gh

Folder path looks fine, files also looks good i don’t how can i fix it. Could you help me ? I use graphhoper 0.10-SNAPSHOT. I generete files from script in the same version.


#2

Android from 4.4 (KitKat) does not allow apps to have direct write access on SD cards.

Mapsforge and VTM access the offline map files in read only mode, so this works with SD cards.

To read also GraphHopper graphs in SD card can try before the load:

graphHopper.setAllowWrites(false);