hasrule 0 Newbie Poster

Dear fellow programmers,

I had tried and successfuly created JVM and used JNI from C++ executable. But when I change my C++ executable into a shared library (.so, in UNIX) like this

extern "C" int callFromFakeSID(char* name)
{
JNIEnv *env;
JavaVM * jvm;


env = UART_Display_Java::create_vm(&jvm);
if (env == NULL)
return 1;
jclass clazz;
jint res;
jmethodID method;

static JNINativeMethod mtab[] ={/* listing of native methods */};

clazz = env->FindClass("JComponent");
res = env->RegisterNatives(clazz, mtab, sizeof(mtab)/sizeof(mtab[0]));

printf("print string from UART_Display_Java.so \n");
method = env->GetStaticMethodID(clazz, "testCallFromFakeSID", "(Ljava/lang/String;)V");
if(method != NULL)
env->CallStaticVoidMethod(clazz, method, name); //Calling the javamethod. (I VE DEBUG. THIS IS THE LINE CREATED HOTSPOT ERROR)
//Release resources.
int n = jvm->DestroyJavaVM();

return 0;

}

it created an unpexcted runtime error like below:

$./fake_exec2

print string from UART_Display_Java.so

#

# An unexpected error has been detected by Java Runtime Environment:

#

#  SIGSEGV (0xb) at pc=0x061b64a6, pid=26026, tid=3051490192

#

# Java VM: Java HotSpot(TM) Client VM (1.6.0_03-b05 mixed mode, sharing)

# Problematic frame:

# V  [libjvm.so+0x1b64a6]

#

# An error report file with more information is saved as hs_err_pid26026.log

#

# If you would like to submit a bug report, please visit:

#   http://java.sun.com/webapps/bugreport/crash.jsp

#

when

extern "C" int callFromFakeSID(char* name)

was still an

int main()

, everything was OK.

Should I use socket, instead of JNI, in the library to communicate to Java? Is there still a hope of using JNI?

Thanks,
Hasrul.