I'm extending the Canvas class for a little game I'm writing, and I can't
get the canvas to display. The following code generates an error:
public class BouncingBall extends Canvas{
public static void main(String[] args){
BouncingBall myApp = new BouncingBall();
}
public BouncingBall(){
super();
addNotify();
setBounds(250,250,550,400);
setBackground(Color.white);
setVisible(true);
}
}
Here's the error:
Exception in thread "main" java.lang.NullPointerException: peer
at sun.awt.windows.WCanvasPeer.create(Native Method)
at sun.awt.windows.WComponentPeer.<init>(Unknown Source)
at sun.awt.windows.WCanvasPeer.<init>(Unknown Source)
at sun.awt.windows.WToolkit.createCanvas(Unknown Source)
at java.awt.Canvas.addNotify(Unknown Source)
at BouncingBall.<init>(BouncingBall.java:17)
at BouncingBall.main(BouncingBall.java:10)
I guess I could use a frame or a window, but I'm really more interested in
why this doesn't work than on making my game work right now. Thanks in
advance!
_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing