How to use graphhopper-osm-id-mapping?

the code of my maven project is listed below:

import java.util.List;

import com.graphhopper.GraphHopper;
import com.graphhopper.matching.EdgeMatch;
import com.graphhopper.matching.GPXFile;
import com.graphhopper.matching.LocationIndexMatch;
import com.graphhopper.matching.MapMatching;
import com.graphhopper.matching.MatchResult;
import com.graphhopper.routing.util.CarFlagEncoder;
import com.graphhopper.routing.util.EncodingManager;
import com.graphhopper.storage.GraphHopperStorage;
import com.graphhopper.storage.GraphStorage;
import com.graphhopper.storage.index.LocationIndexTree;
import com.graphhopper.util.GPXEntry;

import static org.junit.Assert.assertTrue;

public class MapMatcher {
// import OpenStreetMap data
public static void main( String[] args ){
	
MyGraphHopper hopper = new MyGraphHopper();
hopper.setOSMFile("./new-york-latest.osm.pbf");
hopper.setGraphHopperLocation("./target/mapmatchingtest");
CarFlagEncoder encoder = new CarFlagEncoder();
hopper.setEncodingManager(new EncodingManager(encoder));
hopper.setCHEnable(false);
hopper.importOrLoad();

// create MapMatching object, can and should be shared accross threads

GraphHopperStorage graph = hopper.getGraphHopperStorage();
LocationIndexMatch locationIndex = new LocationIndexMatch(graph,
                (LocationIndexTree) hopper.getLocationIndex());

MapMatching mapMatching = new MapMatching(graph, locationIndex, encoder);

// do the actual matching, get the GPX entries from a file or via stream
GPXFile gpxFile = new GPXFile();
gpxFile.doImport("nice.gpx");
List<GPXEntry> inputGPXEntries = gpxFile.getEntries();
for(GPXEntry gpx:inputGPXEntries){
	System.out.println(gpx);
}

MatchResult mr = mapMatching.doWork(inputGPXEntries);

// return GraphHopper edges with all associated GPX entries
List<EdgeMatch> matches = mr.getEdgeMatches();
for(EdgeMatch em:matches){
	EdgeIteratorState edge = em.getEdgeState();
	int edgeId = edge.getEdge();
	System.out.println("before");
	System.out.println(edgeId);
    String vInfo = "";
    if (edge instanceof VirtualEdgeIteratorState) {
        // first, via and last edges can be virtual
        VirtualEdgeIteratorState vEdge = (VirtualEdgeIteratorState) edge;
        edgeId = vEdge.getOriginalTraversalKey() / 2;
        vInfo = "v";
    }
    System.out.println("after");
    System.out.println(edgeId);
}
// now do something with the edges like storing the edgeIds or doing fetchWayGeometry etc
System.out.println(hopper.getOSMWay(30));
}

}

I want to visualize my gpx and match result like forum-problem.

And I want to get edge graphhopper ID and corresponding OSM way ID. I looked up in github-id-mapping. I copied MyGraphHopper.java code to my maven project. And used getOSMWay() as MyImport.java mentioned. But something is wrong even with the input 30. The number 240 is long pointer of function getOSMWay().

Exception in thread "main" 2017-03-12 15:38:24,889 [main] ERROR com.graphhopper.storage.RAMDataAccess - edge_mapping, segments:0, bufIndex:240, bytePos:240, segPower:0
java.lang.ArrayIndexOutOfBoundsException: 240
at com.graphhopper.storage.RAMDataAccess.getInt(RAMDataAccess.java:235)
at ADAPTER.MapMatchingDemo.MyGraphHopper.getOSMWay(MyGraphHopper.java:76)
at ADAPTER.MapMatchingDemo.MapMatcher.main(MapMatcher.java:76)

is my code correct? how to solve it?

I checked and found that it was because private DataAccess edgeMapping in MyGraphHopper.java. Its segments.length is 0(in the com.graphhopper.storage->RAMDataAccess.class). So it’s out of index. The only difference between my code and MyImport.java is this

graphHopper.init(CmdArgs.read(args));

I didn’t write this line. And I don’t know the format of args(the function is from com.graphhopper->GraphHopper.class). Could someone give me an example?
Thanks for answering.