我執行的Java方法母語C++
JNI本地方法導致VM崩潰
JNIEXPORT jobjectArray JNICALL myMethod(JNIEnv *env, jclass, //parameters){
int** result = //my function to obtain a matrix n x m of integers
std::vector<jint> tmp;
//fill the vector tmp with matrix integers and deallocate the matrix
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
tmp[m*i + j] = result[i][j];
}
free(result[i]);
}
free(result);
jintArray jResults = env->NewIntArray(tmp.size());
env->SetIntArrayRegion(jResults, 0, tmp.size(), &tmp[0]);
return env->NewObjectArray(tmp.size(), env->GetObjectClass(jResults), 0);
}
它編譯罰款和java成功加載DLL。但我得到這個錯誤在運行時:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x10009a7d, pid=2264, tid=3856
#
# JRE version: 7.0-b147
# Java VM: Java HotSpot(TM) Client VM (21.0-b17 mixed mode, sharing windows-x86)
# Problematic frame:
# C [myDLL.dll+0x9a7d]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as: hs_err_pid2264.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Java result 1
任何想法?
的功能是什麼的Java的聲明是它應該返回一個int [] [] (因爲這是你在return語句中創建的)? –