经过几个小时的尝试解决这个问题,我很难过。我对 Java 有点陌生,可以使用一些帮助。
堆栈跟踪:
java.lang.IllegalStateException: Component must have a valid peer
at java.awt.Component$FlipBufferStrategy.createBuffers(Unknown Source)
at java.awt.Component$FlipBufferStrategy.<init>(Unknown Source)
at java.awt.Component$FlipSubRegionBufferStrategy.<init>(Unknown Source)
at java.awt.Component.createBufferStrategy(Unknown Source)
at java.awt.Canvas.createBufferStrategy(Unknown Source)
at java.awt.Component.createBufferStrategy(Unknown Source)
at java.awt.Canvas.createBufferStrategy(Unknown Source)
at com.mime.crystalnova.Display.render(Display.java:148)
at com.mime.crystalnova.Display.run(Display.java:112)
at java.lang.Thread.run(Unknown Source)
错误似乎与这里的这行代码有关:
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(3);
return;
}
奇怪的是,它在调试时给了我这个错误,然后继续完美运行。通过可运行的 jar 文件启动时它也可以正常工作。