我需要在我的本机代码中创建一个 Java 类的实例。为此,我使用以下 C 代码:
jobject Java_com_mypackage__myClass_myMethod(JNIEnv* env, jobject thiz, jint index){
int fd = pDevs[index].ufds.fd; // fd = open(....); it's a input/eventX file.
jclass class = (*env)->FindClass(env,"com/mypackage/ClassName");
jmethodID mid = (*env)->GetMethodID(env,class,"<init>","(Ljava/lang/String;)V");
return (*env)->NewObject(env,class,mid,(*env)->NewStringUTF(env, pDevs[index].device_path));
}
但是当我调用 myMethod 时,我不断收到致命信号 11 (SIGSEGV)。代码错了吗?