Java lang NoSuchMethodError : SwigDirector for cplex

430 Views Asked by At

For my first attemp to use CP Optimizer with java, when i run my program i get this error message :

Exception in thread "main" java.lang.NoSuchMethodError: SwigDirector_IloIntValueEvalWrapper_eval
at ilog.cp.cppimpl.cp_wrapJNI.swig_module_init(Native Method)
at ilog.cp.cppimpl.cp_wrapJNI.<clinit>(cp_wrapJNI.java:802)
at ilog.cp.cppimpl.IloCP.<init>(IloCP.java:109)
at ilog.cp.IloCP.<init>(IloCP.java:128)
at ilog.cp.IloCP.<init>(IloCP.java:120)
at buffPos.main(buffPos.java:73)

Knowing that I included the needed libraries ILOG.CP.jar and oplall.jar in the library setting of my project in IntelliJ IDEA and also in the environment variable PATH of my windows. I'm using jdk 15.0.1

The part of my program using iloIntVar is :

// define new model
            IloCP modelPos = new IloCP();

            // variables
            IloIntVar[][] x = new IloIntVar[ligne + 1][];

            for (int i = 0; i < ligne + 1; i++) {
                x[i] = modelPos.boolVarArray(colone + 1);
            }

            IloIntVar[][] a = new IloIntVar[ligne + 1][colone + 1];
2

There are 2 best solutions below

3
supernova On
  1. Would be good to post your complete main Method content as there is the root for your Exception.

2a) If it's static code: Try to see if classes have been loaded in the JVM (or even which class from which JAR lib). Ru your Java application with the - verbose option:

java -verbose ...

2b) Check in the Run Configurations which classes and libs have been configured. Maybe the lib is not included there (top right corner next to the green run triangle). 'edit configuration' and look into the classpath.

2c) It would be helpful to get an understanding if you use any package control system (Maven etc.)

3a) As there's JNI involved - make sure classes AND methods that are called are available as the "NoSuchMethodError" is throws in a method cannot be found in the JVM when called by JNI. Unfortunately not all infos is available in your snippet to debug your code. But it's very likely somethings called wrong here.

0
Ying Liu On

Probably, you miss the configuration of "-Djava.library.path"

If you use IntelliJ IDEA,

first, add the ILOG.CP.jar (you have done it)

then, please add "-Djava.library.path="(your cplex path)\cplex\bin\x64_win64;(your cplex path)\cpoptimizer\bin\x64_win64" in the Run -> Configurations -> VM options of IDEA.

e.g., -Djava.library.path="D:\Program Files\IBM\ILOG\CPLEX_Studio128\cplex\bin\x64_win64;D:\Program Files\IBM\ILOG\CPLEX_Studio128\cpoptimizer\bin\x64_win64"