Article View: borland.public.jbuilder.java.swing
Article #7Q: NullPointer Exception in applets (Swing 1.0.3 or 1.1beta)
From: yan zhou
Date: Mon, 24 Aug 1998 00:00
Date: Mon, 24 Aug 1998 00:00
187 lines
5537 bytes
5537 bytes
Hi,
I employed the new Swing release: 1.0.3 or 1.1beta in
applet development.
But, whenever GridControl is used, the applet keeps
throwing exceptions, which is fine in using with swing1.0.1.
I am wondering if anybody has solutions or explanations
to this problem. The exceptions and code are attached.
Thanks in advance.
Yan Zhou
yzhou@mtu.edu
Netscape Communications Corporation -- Java 1.1.5
Type '?' for options.
Symantec Java! ByteCode Compiler Version 210.065
Copyright (C) 1996-97 Symantec Corporation
# Applet exception: exception: java.lang.NullPointerException
java.lang.NullPointerException
at borland.jbcl.view.GridView.addFocusListener(Compiled Code)
at com.sun.java.swing.JComponent.enableSerialization(Compiled Code)
at com.sun.java.swing.JComponent.<init>(Compiled Code)
at com.sun.java.swing.JScrollPane.<init>(Compiled Code)
at com.sun.java.swing.JScrollPane.<init>(Compiled Code)
at borland.jbcl.view.GridView.<init>(Compiled Code)
* at borland.jbcl.control.GridControl.<init>(Compiled Code)
at testGrid.Applet1.<init>(Compiled Code)
at
netscape.applet.DerivedAppletFrame$LoadAppletEvent.dispatch(Compiled
Code)
at java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled
Code)
at java.awt.EventDispatchThread.run(Compiled Code)
at
netscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(Compiled
Code)
# Applet exception: exception: java.lang.NullPointerException
java.lang.NullPointerException
at borland.jbcl.view.GridView.addFocusListener(Compiled Code)
at com.sun.java.swing.JComponent.enableSerialization(Compiled Code)
at com.sun.java.swing.JComponent.<init>(Compiled Code)
at com.sun.java.swing.JScrollPane.<init>(Compiled Code)
at com.sun.java.swing.JScrollPane.<init>(Compiled Code)
at borland.jbcl.view.GridView.<init>(Compiled Code)
* at borland.jbcl.control.GridControl.<init>(Compiled Code)
at testGrid.Applet1.<init>(Compiled Code)
at
netscape.applet.DerivedAppletFrame$LoadAppletEvent.dispatch(Compiled
Code)
at java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled
Code)
at java.awt.EventDispatchThread.run(Compiled Code)
at
netscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(Compiled
Code)
The following code does nothing but add a grid into applet.
It works fine with swing 1.0.1, but not with swing 1.0.3 or
swing 1.1beta.
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
//import com.sun.java.swing.UIManager;
public class Applet1 extends JApplet {
boolean isStandalone = false;
BorderLayout borderLayout1 = new BorderLayout();
BevelPanel bevelPanel1 = new BevelPanel();
GridControl gridControl1 = new GridControl();
BorderLayout borderLayout2 = new BorderLayout();
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public Applet1() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//static {
// try {
// //UIManager.setLookAndFeel(new
com.sun.java.swing.plaf.metal.MetalLookAndFeel());
// //UIManager.setLookAndFeel(new
com.sun.java.swing.plaf.motif.MotifLookAndFeel());
// UIManager.setLookAndFeel(new
com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
// }
// catch (Exception e) {}
//}
//Component initialization
private void jbInit() throws Exception {
this.getContentPane().setLayout(borderLayout1);
bevelPanel1.setLayout(borderLayout2);
gridControl1.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(FocusEvent e) {
gridControl1_focusGained(e);
}
});
gridControl1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(KeyEvent e) {
gridControl1_keyPressed(e);
}
});
gridControl1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
gridControl1_mouseClicked(e);
}
});
this.getContentPane().add(bevelPanel1, BorderLayout.CENTER);
bevelPanel1.add(gridControl1, BorderLayout.CENTER);
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
void gridControl1_focusGained(FocusEvent e) {
}
void gridControl1_keyPressed(KeyEvent e) {
}
void gridControl1_mouseClicked(MouseEvent e) {
}
}
Technical Details
Message-ID:
<35E19FC5.366B8FC5@mtu.edu>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,72ede45acf0b93e,start X-Google-Attributes: gid111d45,public X-Google-Thread: ff01d,72ede45acf0b93e,start X-Google-Attributes: gidff01d,public From: yan zhou <yzhou@mtu.edu> Subject: Q: NullPointer Exception in applets (Swing 1.0.3 or 1.1beta) Date: 1998/08/24 Message-ID: <35E19FC5.366B8FC5@mtu.edu> X-Deja-AN: 384250000 Content-Transfer-Encoding: 7bit Organization: Another Netscape Collabra Server User Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing,borland.public.jbuilder.applet-issues