线程中的异常(java.lang.IllegalStateException)

时间:2014-05-05 20:59:44

标签: java

我有一些问题。每当我使用JFrame.DISPOSE_ON_CLOSE(而不是EXIT_ON_CLOSE)时,我在关闭窗口时会收到此错误消息:

Exception in thread "Thread-2" java.lang.IllegalStateException: Buffers have not been created
        at sun.awt.windows.WComponentPeer.getBackBuffer(Unknown Source)
        at java.awt.Component$FlipBufferStrategy.getBackBuffer(Unknown Source)
        at java.awt.Component$FlipBufferStrategy.updateInternalBuffers(Unknown Source)
        at java.awt.Component$FlipBufferStrategy.revalidate(Unknown Source)
        at java.awt.Component$FlipBufferStrategy.revalidate(Unknown Source)
        at java.awt.Component$FlipBufferStrategy.getDrawGraphics(Unknown Source)
        at de.hsb.prog2.main.GameLoop.render(GameLoop.java:100)
        at de.hsb.prog2.main.GameLoop.run(GameLoop.java:151)
        at java.lang.Thread.run(Unknown Source)

我认为它与此代码有关:

private void render()
{
   BufferStrategy bufferStrategy = this.getBufferStrategy();
   if (bufferStrategy == null)
   {
       this.createBufferStrategy(3);
       return;
   }

   Graphics g = bufferStrategy.getDrawGraphics();

   /////DRAW HERE/////DRAW HERE/////DRAW HERE/////DRAW HERE/////DRAW HERE/////

   if (Debugger.isDebugging())
   {
       g.setColor(Color.orange);
       g.fillRect(0, 0, getWidth(), getHeight());
       objectHandler.render(g);
   }

   /////DRAW HERE/////DRAW HERE/////DRAW HERE/////DRAW HERE/////DRAW HERE/////

   g.dispose();
   bufferStrategy.show();           

}

也许有人可以给我一些关于如何解决这个故障的暗示。

0 个答案:

没有答案