0
votes

My JNI code consists of calling some java functions (.jar file) from a C++ main.

The code compiles well, but during execution i get :

Segmentation fault (core dumped)

i ran GNU gdb to debug and i found the following during the call of this method :

if(mid != 0) {
doub = env->CallIntMethod(cls,mid,10);

Program received signal SIGSEGV, Segmentation fault. 0x00000000678856ed in jvm!JNI_GetCreatedJavaVMs () from /cygdrive/c/Program Files/Java/jdk1.8.0_05/jre/bin/server/jvm.dll

I also checked if the class is found (JNI FindClass function) and if the JVM is created (JNI_CreateJavaVM function) through the return value, and everything seems to be just fine.

At the end of the debugging the threads exit with code 35584 :

[Thread 4632.0x1304 exited with code 35584]

I didn't find anything about this value except that it implies a problem in the path to something required by the executable ... Any ideas about this ? I specified the path for the .jar file as following :

char op[] = "-Djava.class.path=D:\\path\\tojar/MyJar.jar;D:\\path\\toclass";
options[0].optionString = op;

Thank you StackOverflowers :)

ps : if you think that posting the code can help please notify me in the comments !

1

1 Answers

2
votes

CallIntMethod expects the first argument to be the receiver (i.e. this) object.
When the method you call is static, use CallStaticIntMethod.