所以我试图通过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
如果有人可以提供帮助,我会感到茫然,并会非常感激:)
答案 0 :(得分:3)
Instanitiate rengine如下所示,我刚刚将默认大小设为10。
String args1[] = new String[10];
Rengine rengine = new Rengine(args, false, null);
答案 1 :(得分:0)
您必须在R_HOME
中设置环境变量JVM environment
。将它设置在您的环境变量中无法正常工作,JVM NOT 。我自己想出来了。