So I’m trying to run a server in Eclipse and get this error when I run it.
java.lang.NullPointerException
[1/19/13 9:07 PM]: at com.rs2.util.Misc.loadScripts(Misc.java:544)
[1/19/13 9:07 PM]: at com.rs2.Server.run(Server.java:129)
[1/19/13 9:07 PM]: at java.lang.Thread.run(Thread.java:662)
Here is line 129 in Server.java:
Misc.loadScripts(new File("./data/ruby/"));
And here is the line 544 in loadScripts:
engine.eval(new FileReader(file));
And, in case it’s needed, here is the rest of the loadScripts class:
public static void loadScripts(File directory) {
try {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("jruby");
if (!directory.exists() || !directory.isDirectory()) {
throw new IllegalArgumentException("Missing scripts folder! " + directory.getAbsolutePath());
}
for (File file : directory.listFiles()) {
if (file.isDirectory()) {
loadScripts(file);
} else {
if (file.getName().endsWith(".rb")) {
engine.eval(new FileReader(file));
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (ScriptException e) {
e.printStackTrace();
}
}
If anyone can help, please answer. Thanks in advance.
This happens because
engineisnullwhen line 544 is executed:And it’s
nullbecause theScriptEngineManagerdidn’t find the JRuby scripting engine, that you were trying to load in this line:Make sure that the JRuby script engine is included on the classpath when you run this program.
You should also add a check in your program, for example like this: