import org.jsfml.window.*;
import org.jsfml.graphics.*;
import org.jsfml.internal.*;
import org.jsfml.window.event.Event;
public class Jsmql {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws InterruptedException, ContextActivationException {
// TODO code application logic here
VideoMode vm = new VideoMode(100, 100);
Window fen = new Window(vm, "aaa");
while(fen.isOpen()) {
fen.display();
Event event = fen.pollEvent();
if (event.type == Event.Type.CLOSED) {
fen.close();
}
}
}
}
我想用Java中的JSML创建Java窗口(http://pdinklag.de/jsfml/) 在我的代码发布时,我有以下例外:
线程“main”中的异常java.lang.NullPointerException at jsmql.Jsmql.main(Jsmql.java:29) /Users/me/Library/Caches/NetBeans/8.1/executor-snippets/run.xml:53: Java返回:1 BUILD FAILED(总时间:0秒)
我查看了Java NullPointerException的含义,但我没有成功解决我的问题。
答案 0 :(得分:0)
如果您查看 Window.pollEvent() method的文档,您可以看到它说:
返回当前在事件堆栈顶部的事件,如果没有
,则返回null
因此,在访问event
属性之前,应检查type
是否为空:
if (event != null && event.type == Event.Type.CLOSED) {
fen.close();
}