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个参数,一个是long,另一个是boolean。这个类有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 class created and SWIGTYPE p void constructor is NULL 然后它给出了这个错误:
Java Runtime Environment检测到致命错误:
SIGSEGV(0xb)at pc = 0x00007f7ec503fa7b,pid = 25307, TID = 140182441326336
JRE版本:Java(TM)SE运行时环境(7.0_65-b17)(构建 1.7.0_65-b17)Java VM:Java HotSpot(TM)64位服务器VM(24.65-b04混合模式linux-amd64压缩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中止(核心倾销)
答案 0 :(得分:2)
您找到constructor
方法ID;但是你声称这个类没有构造函数。这意味着,GetMethodID(env,local,"<init>","(V)V")
将返回 0 。要为没有参数的方法指定签名,请使用"()V"
。