所以我试图通过 JRI 从 Java 中使用 R。我正在为 Eclipse 使用 RJava 插件,并且 rJava 附带的两个测试文件工作正常(rtest 和 rtest2)。但是当尝试运行这个简单的代码片段时,我得到一个 EXCEPTION_ACCESS_VIOLATION:
public static void main(String... args) {
Rengine re = new Rengine();
if (!re.waitForR()) {
System.out.println("Unable to load R");
return;
} else
System.out.println("Connected to R");
re.eval("x=c(1:10)");
double d = re.eval("mean(x)").asDouble();
System.out.println(d);
}
我得到的输出:
Connected to R
A fatal error has been detected by the Java Runtime Environment:
EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006c726096, pid=5284, tid=7868
JRE version: Java(TM) SE Runtime Environment (8.0_25-b18) (build 1.8.0_25-b18)
Java VM: Java HotSpot(TM) 64-Bit Server VM (25.25-b02 mixed mode windows-amd64 compressed oops)
Problematic frame:
C [R.dll+0x26096]
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:
C:\Users\gebruiker\workspace64\RTest\hs_err_pid5284.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.
完整日志: http: //pastebin.com/18wHWihB
我在日志中看到了这个,它必须做些什么吗?(错误使用了 eval 函数?我只是复制了一个例子......)
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j org.rosuda.JRI.Rengine.rniParse(Ljava/lang/String;I)J+0
j org.rosuda.JRI.Rengine.eval(Ljava/lang/String;Z)Lorg/rosuda/JRI/REXP;+53
j org.rosuda.JRI.Rengine.eval(Ljava/lang/String;)Lorg/rosuda/JRI/REXP;+3
j Main.main([Ljava/lang/String;)V+35
v ~StubRoutines::call_stub
如果有人可以提供帮助,我很茫然,将不胜感激:)