两次调用后,Jni方法崩溃了JVM

时间:2011-11-25 08:53:35

标签: java c++ crash jvm java-native-interface

好吧,我的问题是我有一个C ++方法,我使用Jni从我的Java应用程序调用。问题是该方法在第一次调用时运行良好,但是当它第二次调用时,JVM崩溃。显示错误:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x77d0e39e, pid=3776, tid=3100
#
# JRE version: 6.0_29-b11
# Java VM: Java HotSpot(TM) Client VM (20.4-b02 mixed mode, sharing windows-x86 )
# Problematic frame:
# C  [ntdll.dll+0x2e39e]
#
# An error report file with more information is saved as:
# C:\Users\OPTIMAL1\workspace\XtremeGUI\hs_err_pid3776.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

这是使用Jni从我的Java应用程序调用的C ++方法:

JNIEXPORT void JNICALL Java_MainFrame_Jni_Functions_displayParameterResults  (JNIEnv *env, jobject obj){

cout << "begin!!!!!!!!!!!!!!" << endl;

cout << "before!!!!!!!!!!!!!!" << endl;
jclass jclazz = env->FindClass("MainFrame/Jni/TablesObjects");
cout << "after***************" << jclazz <<endl;


int size = xtremeDataGA.resultsData.parameter.size();
jdouble* jdbl = new jdouble(size);
for(int i=0; i<size; i++)
    jdbl[i] = xtremeDataGA.resultsData.parameter.at(i).at(0).at(0);
jdoubleArray jdblArr = env->NewDoubleArray(size);
env->SetDoubleArrayRegion(jdblArr, 0, size, jdbl);


jclass jStringClass   = env->FindClass("java/lang/String"); 
jobjectArray jStringArray = env->NewObjectArray(6, jStringClass, 0);
for(int i=0; i<6; i++)
    env->SetObjectArrayElement(jStringArray, i, env->NewStringUTF("a") );


jmethodID mid = env->GetStaticMethodID(jclazz, "resultsParameterInsertCol", "([Ljava/lang/Object;[D)V");
env->CallStaticVoidMethod(jclazz, mid, jStringArray, jdblArr);

cout << "end!!!!!!!!!!!!!!" << endl;
}

编辑:问题已解决。没有任何语法/编码错误。该错误是由于我需要在本地重新声明的全局对象声明。

0 个答案:

没有答案