java在调试生成中使用JNI函数运行C++应用程序导致分割错误
我有一个C++应用程序,它使用JNI访问java函数。 只要我在发布版中构建我的应用程序一切都很好,可以正常工作。但是,当我在调试中构建应用程序时,应用程序在调用jni代码时就会崩溃
我正在使用Ubuntu14.04x64下的QTCreator和GCC4.8.2以及Java1.7.0_75
示例方法e:
void JNICommunicator::queryJNI_deleteIndividual(std::string path, std::string individualName){
if(jvmStatus != JNI_ERR){
jclass cls = env->FindClass("de/myclasspacked/MyClass"); //when getting to this point, the application crashes
if(env->ExceptionOccurred()){
env->ExceptionDescribe();
}
if(cls != 0){
jmethodID constructor = env->GetMethodID(cls, "<init>", "()V");
jobject object = env->NewObject(cls, constructor);
jmethodID mAC = env->GetMethodID(cls, "deleteIndividual", "(Ljava/lang/String;Ljava/lang/String;)V");
if(mAC != 0){
jstring path = env->NewStringUTF(owlPath.c_str());
jstring individualNameTemp = env->NewStringUTF(individualName.c_str());
jobject jAdd = env->CallObjectMethod(object, mAC, path, individualNameTemp);
if(env->ExceptionOccurred()){
env->ExceptionDescribe();
}
}
}
}
}
你知道它为什么会崩溃,或者我如何让应用程序在调试下工作吗?如果没有使用调试功能的能力,开发应用程序是很困难的
谢谢 致意
我从这里得到我的环境。以下是我启动JVM的方式:
void initJVM(){
std::string dPath = "-Djava.class.path=/svn/owl/OWLApiExample/bin";
char *cstr = new char[dPath .length()+1];
strcpy(cstr, dPath .c_str());
options[0].optionString = cstr;
options[1].optionString = "-Djava.library.path=/svn/owl/OWLApiExample/lib";
options[2].optionString = "-verbose:jni";
vm_args.version = JNI_VERSION_1_6;
vm_args.nOptions = 1;
vm_args.options = options;
vm_args.ignoreUnrecognized = 0;
JNI_GetDefaultJavaVMInitArgs(&vm_args);
jvmStatus = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if(jvmStatus != JNI_ERR){
//log
}else{
jsize nVMs;
jvmStatus = JNI_GetCreatedJavaVMs(NULL, 0, &nVMs); // 1. just get the required array length
jvmStatus = JNI_GetCreatedJavaVMs(&jvm, nVMs, &nVMs); // 2. get the data
jvmStatus = jvm->GetEnv((void **)&env, JNI_VERSION_1_6);
if (jvmStatus == JNI_EDETACHED){
if (jvm->AttachCurrentThread((void **) &env, NULL) != 0) {
//log
}else{
}else if (jvmStatus == JNI_EVERSION) {
//log
}
}
}
共 (0) 个答案