Illegal State Exception when creating new Bufferstrategy

前端 未结 3 662
陌清茗
陌清茗 2020-12-03 22:35

When I am trying to figure out how to use bufferstrategies, and overall just improving how I write my code and cleaning things up. When I run the following code, I get an er

3条回答
  •  渐次进展
    2020-12-03 23:35

    Taking a look at the API, this exception is thrown if the component is not displayable. In this case, that's when Canvas.peer is null. Taking a look at the peer field reveals that

    The peer is set when the Component is added to a container that also is a peer

    Since you are starting the update thread from your component's constructor, render could be called before your component is ever added to another container which would mean the peer is null, and then an IllegalStateException would be thrown.

提交回复
热议问题