/** * example1.java - an example of an unchecked (Null Pointer) exception * @author Richard S. Huntrods * @date June 13, 2001 * @version 1.0 * */ import java.applet.*; import java.awt.*; import java.awt.event.*; public class Example1 extends Frame { // declare two instance Labels private Label label1; private Label label2; public Example1() { // instantiate label1 label1 = new Label("Greetings"); // label1 is instantiated. It will work fine add(label1); // label2 has not been instantiated. It will generate the exception add(label2); setSize(200, 100); show(); } public static void main(String[] args) { Example1 ex1 = new Example1(); ex1.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); } }