2014-12-01 41 views
0

所以我試圖通過JRI使用從Java的R。我爲Eclipse使用RJava插件,rJava附帶的兩個測試文件工作正常(rtest和rtest2)。但是,試圖運行這個簡單的代碼片段的時候,我得到一個EXCEPTION_ACCESS_VIOLATION:EXCEPTION_ACCESS_VIOLATION當試圖使用RJAva

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 

如果有人可以幫助,我在一個損失將不勝感激:)

回答

3

Instanitiate rengine像下面,我剛剛做了10作爲默認大小。

String args1[] = new String[10]; 
Rengine rengine = new Rengine(args, false, null); 
+0

非常感謝! – Koekje 2014-12-08 21:06:11

0

你必須設置環境變量R_HOMEJVM environment。將它設置在你的環境變量中將不起作用,JVM是不是的那個。我自己就明白了。