The Artima Developer Community
Sponsored Link

Java Answers Forum
The use of "java.awt.Canvas"

2 replies on 1 page. Most recent reply: Feb 20, 2004 1:50 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

The use of "java.awt.Canvas" Posted: Feb 15, 2004 8:55 AM
Reply to this message Reply
Advertisement
this code

public class CanvasTest extends java.awt.Canvas {
public CanvasTest() {
super ();
super.addNotify();
}
public static void main (String[] args) {
new CanvasTest();
}
}

generates the following exception:
java.lang.NullPointerException: peer
at sun.awt.windows.WCanvasPeer.create(Native Method)
at sun.awt.windows.WComponentPeer.<init>(WComponentPeer.java:509)
at sun.awt.windows.WCanvasPeer.<init>(WCanvasPeer.java:29)
at sun.awt.windows.WToolkit.createCanvas(WToolkit.java:359)
at java.awt.Canvas.addNotify(Canvas.java:74)
at CanvasTest.<init>(CanvasTest.java:16)
at CanvasTest.main(CanvasTest.java:19)


Can anyone tell me why this is so?
I'm using a software (jintegra) wich allows me to access COM functions.
One of the Classes generated from the .exe file can only be used after executing the addNotify method.


Patrik Larsson

Posts: 4
Nickname: mrx
Registered: Jan, 2004

Re: The use of "java.awt.Canvas" Posted: Feb 19, 2004 11:17 AM
Reply to this message Reply
Hi!

I think you get this error because you just type "new CanvasTest" in main, instead you should write the main method like this:

public static void main(String[] args){
CanvasTest c = new CanvasTest();

This main method will not have any compilererrors.
Another thing that might be the cause for this error is that you should only use addNotify(); when you have like a frame as superclass. Besides these remarks everything looks fine to me. Be aware this might not solv you errormessage, but it sure will make the code more correct in syntax.

mrx out.

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: The use of "java.awt.Canvas" Posted: Feb 20, 2004 1:50 AM
Reply to this message Reply
So I have to use a frame to make it work.
thx.

Flat View: This topic has 2 replies on 1 page
Topic: embed netscape browser into a java application Previous Topic   Next Topic Topic: servlet background images

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use