java.lang.IllegalArgumentException: Could not create weighting for profile

Hello there! I’m trying to load my ghz file to GraphHopper, but it doesn’t want to start. Can someone help me please with it?

There is Kotlin code where I provide location and profile to it.

val graphHopper = GraphHopper()
graphHopper.setGraphHopperLocation(location)
grapHopper.setProfiles(Profile("my"),setCustomModel(customModel)
graphHopper.load()
}

But I get this error and I don’t know how to deal with it.

exception
java.lang.IllegalArgumentException: Could not create weighting for profile: ‘car’.
Profile: … (created profile description)
Error: Cannot compile expression: can’t load this type of class file
at com.graphhopper.GraphHopper.checkProfilesConsistency(GraphHopper.java:1086)
at com.graphhopper.GraphHopper.load(GraphHopper.java:1061)

Are you running this on Android or something? The janino library used by GraphHopper might be incompatible with the Android JVM.

1 Like

Yes, janino does not work on Android. See this comment.

However on the server or desktop you can use janino to create your own Weighting class and bundle the created code inside the jar file and use this for the weighting instead of custom (which uses janino). This avoids that janino is needed on Android. But this forces you to update the jar file whenever you update the weighting. See this discussion about iOS (but applies to Android too).

1 Like

Yep, I’m running it on Android.
I solved this problem with changing:

return sc.getClassLoader().loadClass("com.graphhopper.routing.weighting.custom.JaninoCustomWeightingHelperSubclass" + counter);

on

return sc.getClassLoader().loadClass("com.graphhopper.routing.weighting.custom.CustomWeightingHelper");

in CustomModelParser.createClazz() method
and it started to work.

CustomWeightingHelper won’t give you a proper weighting. Do you really get proper routes and times?

Routes are proper. I can’t say anything about times, becouse I don’t use it.

I don’t see how this can work. As you don’t seem to use CH or LM so there are no pre-calculated weights.

Thanks for your response, I’ll try to do it.
Have a good day!