gpt4 book ai didi

java - jni getMethodID 用于获取构造函数 ID 时返回 Null

转载 作者:行者123 更新时间:2023-11-30 03:41:54 25 4
gpt4 key购买 nike

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 个参数,第一个是长整型,第二个是 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 类,并且 SWIGTYPE p void 构造函数为 NULL,然后给出了此错误:

A fatal error has been detected by the Java Runtime Environment:

SIGSEGV (0xb) at pc=0x00007f7ec503fa7b, pid=25307, tid=140182441326336

JRE version: 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) Problematic frame: V [libjvm.so+0x657a7b] JNI_ArgumentPusherVaArg::JNI_ArgumentPusherVaArg(_jmethodID*, __va_list_tag*)+0x1b

Core dump written. Default location: /home/manish/rathi/libdmc/dmcore/include/core or core.25307

An error report file with more information is saved as: /home/manish/rathi/libdmc/dmcore/include/hs_err_pid25307.log

If you would like to submit a bug report, please visit:
http://bugreport.sun.com/bugreport/crash.jsp

Aborted (core dumped)

最佳答案

您找到constructor方法ID;但你声称这个类没有构造函数。这意味着 GetMethodID(env,local,"<init>","(V)V")将返回0。要为不带参数的方法指定签名,请使用 "()V" .

关于java - jni getMethodID 用于获取构造函数 ID 时返回 Null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26656653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com