Name: stC104175 Date: 06/29/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
Build an applet from the code below and use it in an HTML page.
Source Code:
-----------------------------------------
import java.awt.*;
import java.applet.*;
import java.net.URL;
public class Applet1 extends Applet
{
public Applet1() {
System.out.println("Constructor here!");
URL codeBase;
codeBase=getCodeBase();
}
/*
public void init() {
System.out.println("Constructor here!");
URL codeBase;
codeBase=getCodeBase();
}
*/
}
-----------------------------------------
Error message/trace:
-----------------------------------------
Java(TM) Plug-in: Version 1.3.0-C
Using JRE version 1.3.0 Java HotSpot(TM) Client VM
User home directory = C:\WINNT\Profiles\Armand
...
java.lang.NullPointerException
at java.applet.Applet.getCodeBase(Unknown Source)
at Applet1.<init>(Applet1.java)
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
-----------------------------------------
Other info:
-----------------------------------------
1. To see the problem with 'getDocumentBase()', use it in the above code in
place of 'getCodeBase().'
2. This is a condensation of the same problem that occurred to me while trying
to get Example 11-08 on page 604 of "Graphic Java 2" by David M. Geary,
published by Sun Microsystems Press, 1999, to work.
3. I have found similar things in the bug database that were never confirmed.
4. I have tried to find some documentation on the role of constructors in
Applets/JApplets to no avail. It would be helpful to know where to find it.
-----------------------------------------
Thanks.
(Review ID: 106661)
======================================================================