我试着运行这个例子从Renjin网站,http://www.renjin.org/documentation/developer-guide.html,Im运行第一个“简单入门”的例子。
以下是我的目录布局:

这是我的密码:
package stackoverflow;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import org.renjin.sexp.*; // <-- import Renjin's object classes
/**
*
* @author yschellekens
*/
public class StackOverflow {
public static void main(String[] args) throws Exception {
ScriptEngineManager factory = new ScriptEngineManager();
// create a Renjin engine
ScriptEngine engine = factory.getEngineByName("Renjin");
// evaluate R code from String, cast SEXP to a DoubleVector and store in the 'res' variable
DoubleVector res = (DoubleVector)engine.eval("a <- 2; b <- 3; a*b");
System.out.println("The result of a*b is: " + res);
}
}为什么我会得到下面的例外?(我应该得到6)
run:
Exception in thread "main" java.lang.NullPointerException
at stackoverflow.StackOverflow.main(StackOverflow.java:22)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)提前感谢
发布于 2014-05-21 12:18:58
例外情况是抛出,因为应用程序找不到Renjin ScriptEngine。您已经将renjin作为一个库提供了,但是您需要从http://build.bedatadriven.com/job/renjin/lastSuccessfulBuild/org.renjin$renjin-script-engine/ (使用带有依赖项的JAR )中获得的renjin脚本引擎库。
不幸的是,ScriptEngineManager.getEngineByName()只在找不到引擎时才返回null,因此您可以添加以下检查以确保引擎已加载:
// check if the engine has loaded correctly:
if(engine == null) {
throw new RuntimeException("Renjin Script Engine not found on the classpath.");
}也要注意:它叫仁进,不是仁进!
https://stackoverflow.com/questions/23592839
复制相似问题