今天我得到一个任务,通过 c 例程调用 java 方法。目前我正在通过 java 调用 ac 例程,我从那里调用 java 方法,而不是出现致命错误
#A fatal error has been detected by the Java Runtime Environment:
# SIGSEGV (0xb) at pc=0x00002b170bae1d66, pid=10052, tid=47378050390336
JRE version: 7.0_21-b11
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.21-b01 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libHelloImpl.so+0xd66] process_message+0xdb
#
我调用java方法的代码是
JNIEXPORT Java_com_example_mail_MailProcessingEngine_intializeMTADequeueDaemon(JNIEnv *jniEnv, jobject obj)
{
jclass mailProcessingClass;
jmethodID callingMethod;
jobjectArray applicationArgs;
jstring applicationArg0;
mailProcessingClass = (*jniEnv)->FindClass(jniEnv, "com/example/mail/MailProcessingEngine");
printf("\nhelloWorldClass-%d",mailProcessingClass);
callingMethod = (*jniEnv)->GetStaticMethodID(jniEnv,mailProcessingClass, "processMail", "(I)I");
printf("\nmainMethod-%d",callingMethod);
if (callingMethod == 0) {
printf("Could not find Method\n");
}else{
printf("FInd Method");
}
int isSuccess = (*jniEnv)->CallStaticIntMethod(jniEnv, mailProcessingClass, callingMethod, 6);
printf("IsSuccess - "+isSuccess);
}
我的 Java 类是
package com.example.mail;
public class MailProcessingEngine {
public native void intializeMTADequeueDaemon();
static { System.loadLibrary("MailerImpl"); }
public static void main (String[] args) {
MailProcessingEngine mailProcessingEngine = new MailProcessingEngine();
mailProcessingEngine.intializeMTADequeueDaemon();
}
public static int processMail(int mailId){
System.out.println("MailId :"+mailId);
return 1;
}
}
谁能告诉我这里出了什么问题。毕竟我们可以用相同的 jni 环境引用来回调 java 方法。
谢谢, Ashish Panery