Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行c++;在调试构建中使用JNI函数的应用程序会导致分段错误 我有一个C++应用程序,它使用JNI访问java函数。 只要我在发布版中构建我的应用程序一切都很好并且正常工作。但是,当我在调试中构建应用程序时,应用程序在调用jni代码时立即崩溃_Java_C++_Debugging_Segmentation Fault_Java Native Interface - Fatal编程技术网

运行c++;在调试构建中使用JNI函数的应用程序会导致分段错误 我有一个C++应用程序,它使用JNI访问java函数。 只要我在发布版中构建我的应用程序一切都很好并且正常工作。但是,当我在调试中构建应用程序时,应用程序在调用jni代码时立即崩溃

运行c++;在调试构建中使用JNI函数的应用程序会导致分段错误 我有一个C++应用程序,它使用JNI访问java函数。 只要我在发布版中构建我的应用程序一切都很好并且正常工作。但是,当我在调试中构建应用程序时,应用程序在调用jni代码时立即崩溃,java,c++,debugging,segmentation-fault,java-native-interface,Java,C++,Debugging,Segmentation Fault,Java Native Interface,我正在使用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/MyClas

我正在使用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();
                }
            }
        }
    }
}

你从哪里得到你的
env
值?嘿,安德鲁,我更新了我的帖子。
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
    }
}
}