Jump to content

  • Log In with Google      Sign In   
  • Create Account

[java] java.lang.IllegalStateException: Component must have a valid peer


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Addictman   Members   -  Reputation: 218

Like
0Likes
Like

Posted 04 August 2004 - 07:31 AM

Does anyone know what could cause this exception at the lines below? It happens seemingly at random. I guess the bufferstrategy is not displayable or "flippable"/"blittable", IE: The buffers are not ready. But I cannot really say why... BufferStrategy bufferStrat = myWindow.getBufferStrategy(); if(!bufferStrat.contentsLost()) bufferStrat.show(); Ideas anyone?

Sponsor:

#2 vovansim   Members   -  Reputation: 336

Like
0Likes
Like

Posted 04 August 2004 - 08:35 AM

Hi,

Hmmm.... I had that same problem a couple times...

The problem is when you call getBufferStrategy, the first call eventually trickles down to the Component's createBuffers function. Now, that function, must call the Component's peer member's function of the same name, which of course cannot be done if the peer is null. The question is then, when does the peer get set? Well, that happens, according to the documentation:


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


Well, then, I guess what that means is that if you want to get the buffer strategy of a window, then you can't do it until you call the window.setVisible(true), or the show function, because if I am not mistaken, that's when the top-level window obtains it's "peer".

In other words, for instance, this code:


JFrame frame = new JFrame("Test Frame");
BufferStrategy strat = frame.getBufferStrategy();



would produce exactly the exception you are seeing.

Vovan

PS: Of course, I am no expert on Java, so I might be wrong. :)

#3 Addictman   Members   -  Reputation: 218

Like
0Likes
Like

Posted 04 August 2004 - 09:13 AM

Thanks, I'll try to dig through the code to find out where I am letting this glitch through ;)

#4 garazdawi   Members   -  Reputation: 145

Like
0Likes
Like

Posted 04 August 2004 - 09:50 AM

Inorder for you to get the BufferStrategy of any Component, the component has to be visible. Otherwise no BufferStrategy can be created for you to use...




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS