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;
}