Okay, I haven't had a chance to thoroughly analyze this, but I can see
that there is something wrong with the super.actionPerformed (aevt);
line. My guess is that somehow the action event you're passing to the is
not properly instantiated, or something along the lines of needing to
supply a no arguments constructor. Failure to supply a no args
constructor is where I usually run into null pointer exceptions. Sorry
this is sketchy... gotta run.
On Wed, 17 Apr 1996, Daniele Lugli wrote:
> Could somebody try the following application? It raises a null pointer
> exception when class Dialog2, extending class Dialog1, tries to access a
> data member of the outer class.
> Please consider that I am really a java newbie (about 10 days of
> programming) so I'm not saying I've found a bug, the problem is probably
> mine.
>
> Thank you,
> Daniele Lugli
>
>
> // File name: Wrong.java
>
> import java.awt.*;
> import java.awt.event.*;
> import java.lang.String;
> import java.text.*;
> import java.util.*;
>
> public class Wrong extends Frame {
>
> public static void main (String args[]) throws Exception {
> new Wrong ();
> }
>
> public Wrong () throws Exception {
> super ();
> setBounds (300, 100, 300, 100);
> setVisible (true);
>
> i = 5;
>
> new Dialog2 (this);
> }
>
> private void quit () {
> setVisible (false);
> dispose ();
> System.exit (0);
> }
>
>
> class Dialog1 extends Dialog implements ActionListener {
> Dialog1 (Frame parent) {
> super (parent, "Dialog", true );
> setBounds (400, 200, 100, 75);
> okButton = new Button ("OK");
> okButton.addActionListener (this);
> add (okButton);
> setVisible (true);
> }
> public void actionPerformed (ActionEvent aevt) {
>
> System.out.println ("Dialog1: i=" + i);
>
> }
> private Button okButton;
> }
>
> class Dialog2 extends Dialog1 {
> Dialog2 (Frame parent) {
> super (parent);
> }
> public void actionPerformed (ActionEvent aevt) {
> super.actionPerformed (aevt);
>
> System.out.println ("Dialog2: i=" + i);
>
> quit ();
> }
> }
>
> int i;
>
> }
>