Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-1233196

NullPointerException if pack called on Dialog before parent Frame shown/packed

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.0.1
    • CPU:
      sparc
    • OS:
      solaris_2.4
    • Verification:
      Not verified

      Description

      If you create a Dialog object and call pack() on it before calling
      pack() or show() on it's parent Frame, then the program will exit with
      a NullPointerException:

      java.lang.NullPointerException
      at sun.awt.motif.MComponentPeer.<init>(MComponentPeer.java:78)
      at sun.awt.motif.MCanvasPeer.<init>(MCanvasPeer.java:32)
      at sun.awt.motif.MPanelPeer.<init>(MPanelPeer.java:30)
      at sun.awt.motif.MDialogPeer.<init>(MDialogPeer.java:39)
      at sun.awt.motif.MToolkit.createDialog(MToolkit.java:104)
      at java.awt.Dialog.addNotify(Dialog.java:78)
      at java.awt.Window.pack(Window.java:80)
      at DialogTest.<init>(DialogTest.java:13)
      at DialogTest.main(DialogTest.java:27)


      [note: this is only really a problem with applications since applets
      already have their
      ----------------------------------------------------------
      import java.awt.*;

      public class DialogTest extends Dialog {
          public DialogTest(Frame parent) {
      super(parent, "Example Dialog", false);

      setLayout(new BorderLayout());
      add("North", new Label("This is a Simple dialog", Label.CENTER));
      Panel panel = new Panel();
      panel.setLayout(new FlowLayout());
      panel.add(new Button("OK"));
      add("South", panel);
      pack();
          }
          public boolean handleEvent(Event event) {
      switch(event.id) {
      case Event.WINDOW_DESTROY:
      hide();
      return true;
      }
      return super.handleEvent(event);
          }
         
          public static void main(String args[]) {
      Frame frame = new Frame();
      frame.setLayout(new FlowLayout());
      Dialog dialog = new DialogTest(frame);
      frame.pack();
      frame.show();
          }
      }

        Attachments

          Activity

            People

            Assignee:
            amfowler Anne Fowler (Inactive)
            Reporter:
            amfowler Anne Fowler (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: