Java运行时环境检测到致命错误-。异常\u访问\u冲突
当我尝试加载JNIC/C++dll库时,出现了这个错误,我注意到它说“崩溃发生在Java虚拟机之外的本机代码中。”不确定这是什么意思?任何帮助都将不胜感激 Java源代码如下:Java运行时环境检测到致命错误-。异常\u访问\u冲突,java,dll,java-native-interface,Java,Dll,Java Native Interface,当我尝试加载JNIC/C++dll库时,出现了这个错误,我注意到它说“崩溃发生在Java虚拟机之外的本机代码中。”不确定这是什么意思?任何帮助都将不胜感激 Java源代码如下: package demojni; public class Main { static { System.load("C:\\Users\\Nicholas1\\Documents\\NetBeansProjects\\DemoJNI_Lib\\dist\\DemoJNI_Lib.dll"); // L
package demojni;
public class Main {
static {
System.load("C:\\Users\\Nicholas1\\Documents\\NetBeansProjects\\DemoJNI_Lib\\dist\\DemoJNI_Lib.dll"); // Load native library at runtime
// hello.dll (Windows) or libhello.so (Unixes)
}
// Declare a native method sayHello() that receives nothing and returns void
// Test Driver
public static void main(String[] args) {
new Main().sayHelloWorld(); // invoke the native method
}
private native void sayHelloWorld();
}
#include "DemoJNI_Lib.h"
#include <stdio.h>
JNIEXPORT void JNICALL Java_demojni_Main_sayHelloWorld
(JNIEnv * env, jobject obj){
printf("Hello World \n");
}
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class demojni_Main */
#ifndef _Included_demojni_Main
#define _Included_demojni_Main
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: demojni_Main
* Method: sayHelloWorld
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_demojni_Main_sayHelloWorld
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
C源代码如下:
package demojni;
public class Main {
static {
System.load("C:\\Users\\Nicholas1\\Documents\\NetBeansProjects\\DemoJNI_Lib\\dist\\DemoJNI_Lib.dll"); // Load native library at runtime
// hello.dll (Windows) or libhello.so (Unixes)
}
// Declare a native method sayHello() that receives nothing and returns void
// Test Driver
public static void main(String[] args) {
new Main().sayHelloWorld(); // invoke the native method
}
private native void sayHelloWorld();
}
#include "DemoJNI_Lib.h"
#include <stdio.h>
JNIEXPORT void JNICALL Java_demojni_Main_sayHelloWorld
(JNIEnv * env, jobject obj){
printf("Hello World \n");
}
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class demojni_Main */
#ifndef _Included_demojni_Main
#define _Included_demojni_Main
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: demojni_Main
* Method: sayHelloWorld
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_demojni_Main_sayHelloWorld
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
错误日志(hs_err_pid7552.Log):
C/C++项目的生成/链接器选项:
1. Right-click on DemoJNI_Lib project and select properties. Go to Build/C Compiler then look under General/Include Directories and click on directories button(…), then select Add button. Now select the include folder from “C:\Program Files\Java\jdk1.8.0_111\include”, then select Add button and select the win32 folder from “C:\Program Files\Java\jdk1.8.0_111\include/win32”, finally choose OK-button.
2. Right-click on DemoJNI_Lib project and select properties. Go to Build/C-Compiler find “Command Line”/”Additional Options”, then type “-shared –m32”
3. Right-click on DemoJNI_Lib project and select properties “Build”/”Linker”, find “General”/”Output”, then type dist/DemoJNI_Lib.dll
4. Optional:Add typedef long long __int64; or #define __int64 long long to top of DemoJNI_Lib.h file. Should be above #include <jni.h>.
5. Build .dll library file: in Netbeans find C/C++ project with c-file and header-file, then Project->(right click)->Clean and Build.
我们还没有找到使用Cygwin C/C++编译器解决崩溃错误的确切方法,但此错误的替代解决方案是使用Microsoft Visual Studio C/C++编译器 以下是使用Microsoft Visual Studio C/C++编译器的JNI解决方案的链接: 注意:如果您使用Microsoft Visual Studio C/C++编译器进行JNI开发
- 对于32位dll,请使用“C:\Program Files(x86)\Microsoft Visual Studio 14.0\Common7\Tools”中的“vsvars32.bat”
- 对于我的设置,我需要一个64位dll文件,所以我使用了“C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\bin\amd64”中的“vcvars64.bat”
1.从添加-删除程序中删除JAVA 8更新
2.删除临时目录的内容
3.重新启动电脑。
4.立即更新java 8。
5.检查路径
C:\Program Files\Java\jdk1.8.0\U 152\lib
它不应显示文件夹“windows-amd64”。6.现在检查服务器
希望这能有所帮助。请分享您在编译、链接和运行过程中遵循的步骤。感谢Sumeet及时回复我的youtube评论。我用我的JNI项目的编译、链接和运行更新了我的原始问题。谢谢给我一些时间,我会检查一下,你似乎有所有与NetBeans相关的步骤。你试过用我的方法吗?试一试,至少我们会知道你的情况是否正常。它在vsvars32.bat下可用,请检查你是否随身携带bat文件
1. In Netbeans Select DemoJNI java project, Main.java->(Right-click)->Run