Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

NullPointerException: peer  RSS feed

 
Chris Spiking
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know it sounds quite a simply put question, BUT in my code I am trying to add a Component to a JPanel in Swing via the line:
m_jPanel.add( component, BorderLayout.CENTER );
where component is of type Component.
Problem is, I get this error:
java.lang.NullPointerException: peer
at sun.awt.windows.WCanvasPeer.create(Native Method)
at sun.awt.windows.WComponentPeer.<init>(WComponentPeer.java:370)
at sun.awt.windows.WCanvasPeer.<init>(WCanvasPeer.java:36)
at sun.awt.windows.WToolkit.createCanvas(WToolkit.java:280)
at java.awt.Canvas.addNotify(Canvas.java:71)
at java.awt.Container.addNotify(Container.java:1574)
at javax.swing.JComponent.addNotify(JComponent.java:3495)
coming back from the stack trace.
Does anyone know what could be happening?
Thanks!
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Canvas is an awt component. Mixing swing and awt components, usually isn't a safe thing to do. There is no JCanvas but I think you might be able to achieve with JPanel the same thing as with Canvas.
If you don't use Canvas in your code, well... Some sample code from your's might be helpfull.
chantal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!