I have assigned jvm to global variable in a function using
int status = (*jenv)->GetJavaVM(jenv, &jvm);
if(status != 0) {
printf(" Fail!\n");
}
classNameC 是一个全局变量,它的类没有构造函数。然后在其他函数中,我这样使用它:
JNIEnv *env;
printf("starting function\n");
(*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
printf("thread attached\n");
jclass local = (*env)->FindClass(env,classNameC);
if(local!=NULL)
{
printf("1st class found\n");
}
jmethodID constructor=(*env)->GetMethodID(env,local,"<init>","()V");
if(constructor==NULL)
{
printf("1st Constructoris NULL\n");
}
else
{
printf("1st Constructor created\n");
}
jobject classObject=(*env)->NewObject(env,local,constructor);
if(classObject==NULL)
{
printf("1st object is NULL\n");
}
else
{
printf("1st object is created\n");
}
jclass local1 = (*env)->FindClass(env,"SWIGTYPE_p_void");
if(local1==NULL)
{
printf("SWIGTYPE p void class is NULL\n");
}
else
{
printf("SWIGTYPE p void class created\n");
}
这个构造函数有 2 个参数,一个是长的,下一个是布尔值。这个类有 2 个构造函数,另外一个没有参数并且用 0 初始化成员。
jmethodID constructor1=(*env)->GetMethodID(env,local1,"<init>","(J;Z;)V");
if(constructor1==NULL)
{
printf("SWIGTYPE p void constructor is NULL\n");
}
else
{
printf("SWIGTYPE p void constructor is created\n");
}
当我运行它时,它成功打印到创建的 SWIGTYPE p void 类并且 SWIGTYPE p void 构造函数为 NULL ,然后它给出了这个错误:
Java 运行时环境检测到一个致命错误:
SIGSEGV (0xb) 在 pc=0x00007f7ec503fa7b,pid=25307,tid=140182441326336
JRE 版本:Java(TM) SE Runtime Environment (7.0_65-b17) (build 1.7.0_65-b17) Java VM: Java HotSpot(TM) 64-Bit Server VM (24.65-b04 mixed mode linux-amd64 compressed oops) 有问题框架:V [libjvm.so+0x657a7b] JNI_ArgumentPusherVaArg::JNI_ArgumentPusherVaArg(_jmethodID*, __va_list_tag*)+0x1b
核心转储写入。默认位置:/home/manish/rathi/libdmc/dmcore/include/core 或 core.25307
包含更多信息的错误报告文件保存为:/home/manish/rathi/libdmc/dmcore/include/hs_err_pid25307.log
如果您想提交错误报告,请访问:
http ://bugreport.sun.com/bugreport/crash.jsp中止(核心转储)