i trying call ruby function in java. got nullpointerexception
when run program.
here java code
import java.io.ioexception; import java.io.inputstreamreader; import java.io.reader; import javax.script.invocable; import javax.script.scriptengine; import javax.script.scriptenginemanager; import javax.script.scriptexception; import java.io.inputstream; public class myprogram { public static void main(string[] args) throws ioexception, nosuchmethodexception { try { scriptenginemanager mgr = new scriptenginemanager(); scriptengine rbengine = mgr.getenginebyextension("rb"); inputstream = classloader.getsystemresourceasstream("src/myruby.rb"); reader reader = new inputstreamreader(is); rbengine.eval(reader); invocable invocableengine = (invocable)rbengine; if (invocableengine != null) { int set = (integer) invocableengine.invokefunction("myfunc",6,6); } } catch (scriptexception e) { system.out.println("\nscriptexception = "+e); } } }
and myruby.rb file contains
def myfunc(a,b) f=a+b return f end
the error getting is,
exception in thread "main" java.lang.nullpointerexception @ java.io.reader.<init>(unknown source) @ java.io.inputstreamreader.<init>(unknown source) @ myprogram.main(myprogram.java:22)
please me find problem.
in advance.
inputstream = classloader.getsystemresourceasstream("src/myruby.rb");
here, is
null.
try absolute path open file.
if file found, there problem classloader.getsystemresourceasstream
.
Comments
Post a Comment