![](https://i-blog.csdnimg.cn/direct/f40d949fec5e46ada74caa2668eefd79.jpeg)
一、问题场景
当使用 Java 程序调用 C/C++ 程序的 JNI
接口的时候,Java 项目会直接挂掉,然后报错如下:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007ff66f3618b6, pid=52, tid=0x00007ff6239ff640
#
# JRE version: Java(TM) SE Runtime Environment (8.0_421) (build 1.8.0_421-b09)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.421-b09 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# V [libjvm.so+0x6bb8b6] jni_GetStringUTFChars+0x76
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# //hs_err_pid52.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
#
Aborted
二、问题分析
一般地,这类问题是 由底层调用 C/C++ 的 JNI
函数报错导致 的系统错误,与 Java 平台无关。
我们主要关注报错的以下两点,即可看出具体问题:
![](https://i-blog.csdnimg.cn/direct/a7d4f73c28e54d14810a9bea4e661c18.png)
# V [libjvm.so+0x6bb8b6] jni_GetStringUTFChars+0x76
:指的是JNI
函数的GetStringUTFChars
方法报错了。# //hs_err_pid52.log
:指的是报错日志在/hs_err_pid52.log
。
我们根据 GetStringUTFChars
查看报错日志文件,定位到内容如下:
![](https://i-blog.csdnimg.cn/direct/877b24e81e904bce976abf63a96dde5a.png)
- 根据报错信息定位到具体的调用栈。
- 在调用栈的上一层,可以看到是由于
MyComponent
文件中调用SetModelPath
方法报错了,
对应的代码位置如下:
![](https://i-blog.csdnimg.cn/direct/c7584e10f15542408326e88fdec11e99.png)
可以看到,这里是缺少了一个 环境变量 MY_MODEL_PATH
。
三、问题解决
把环境变量 MY_MODEL_PATH
设置为具体的 so
控件的位置路径即可。命令如下:
export MY_MODEL_PATH=/opt/my_component/
整理完毕,完结撒花~ 🌻
参考地址:
1.A fatal error has been detected by the Java Runtime Environment程序错误处理方法,https://blog.csdn.net/qq_23438131/article/details/62864038