Я также использую jdk1.7.0_80
Код: Выделить всё
lang-java
package scripting;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import client.MapleClient;
import tools.FileoutputUtil;
public abstract class AbstractScriptManager {
private static final ScriptEngineManager sem = new ScriptEngineManager(null);
protected Invocable getInvocable(String path, MapleClient c) {
return getInvocable(path, c, false);
}
protected Invocable getInvocable(String path, MapleClient c, boolean npc) {
FileReader fr = null;
try {
path = "scripts/" + path;
ScriptEngine engine = null;
if (c != null) {
engine = c.getScriptEngine(path);
}
if (engine == null) {
File scriptFile = new File(path);
if (!scriptFile.exists()) {
return null;
}
engine = sem.getEngineByName("JavaScript");
if (c != null) {
c.setScriptEngine(path, engine);
}
fr = new FileReader(scriptFile);
engine.eval(fr);
} else if (c != null && npc) {
c.getPlayer().dropMessage(-1, "You already are talking to this NPC. Use @ea if this is
not intended.");
}
return (Invocable) engine;
} catch (Exception e) {
System.err.println("Error executing script. Path: " + path + "\nException " + e);
FileoutputUtil.log(FileoutputUtil.ScriptEx_Log, "Error executing script. Path: " + path +
"\nException " + e);
return null;
} finally {
try {
if (fr != null) {
fr.close();
}
} catch (IOException ignore) {
}
}
}
}
Ошибка выполнения сценария. Путь: scripts/event/someEvent.js Исключение
java.lang.NullPointerException: невозможно вызвать
"javax.script.ScriptEngine.eval(java.io.Reader)", поскольку "engine" имеет значение null
Эти ошибки возникают всякий раз, когда я пытаюсь взаимодействовать с чем-то, использующим этот метод (например, при нажатии на NPC или при запуске сервера при запуске некоторых сценариев).< /п>
Подробнее здесь: https://stackoverflow.com/questions/657 ... ll-in-code