BufferStrategy中非法状态异常 [英] BufferStrategy Illegal State Exception

查看:143
本文介绍了BufferStrategy中非法状态异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的努力工作,这一点我难倒了几个小时后。我有点新的Java和可以使用一些帮助。

After a few hours of trying to work this out I am stumped. I am somewhat new to Java and could use some help.

堆栈跟踪:

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)

该错误似乎与这条线code的位置:

The error appears to be with this line of code here:

BufferStrategy bs = getBufferStrategy();
if (bs == null) {
    createBufferStrategy(3);
    return;
}

奇怪的是,它给我这个错误,而调试,然后继续运行完美。当通过可运行jar文件推出,以及它工作正常。

The odd thing is that it gives me this error while debugging and then continues to run flawlessly. It works fine when launched via runnable jar file as well.

推荐答案

这也可能是得到了与调用时间的成分不被看见没有这样做 createBufferStrategy() (有一阵子了)。尝试在以后调用它。

It's probably got to do with the component not being visible yet at the time you call createBufferStrategy() (it's been a while). Try calling it at a later time.

这应用程式继续可能运行的事实意味着该组件默认为一个非缓冲策略

The fact that your app continues to run probably means the component defaulted to a non-buffered strategy.

这篇关于BufferStrategy中非法状态异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆