BUG: NullPointerException in DialogLayout Constructor

ID: Q167942

The information in this article applies to:

SYMPTOMS

When you try to call your Dialog class constructor and CreateControls() in a Frame Class constructor, the following error appears:

   Java.lang.NullPointerException.

CAUSE

The font for the frame has not been initialized.

RESOLUTION

To workaround the problem create a font object prior to the call to the Dialog box constructor. For example:

   import java.awt.*;
   import NewDialog;

   class MyFrame extends Frame
   {
      NewDialog dlg = null;
      public MyFrame()
      {

         setFont( new Font( "Dialog", Font.PLAIN, 16));

         dlg = new NewDialog(this);
         dlg.CreateControls();
      }
   }

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Behavior

1. Generate an Applet using VJ1.0/1.1 AppletWizard. Remove the

   multi-threaded option and leave everything else as default.

2. Create a new Dialog resource named NewDialog with the default OK
   and Cancel buttons on it. Save it as a .rct file.

3. Run Java Resource Wizard to create the corresponding .java files.

4. Create a new class called MyFrame and extend it from frame:

      import java.awt.*;
      import NewDialog;

      class MyFrame extends Frame
      {
         NewDialog dlg = null;
         public MyFrame()
         {
            dlg = new NewDialog(this);
            dlg.CreateControls();
         }
      }

5. In the Applet class instantiate the frame class as:

      MyFrame frame = null;

6. In the Applets init() function call:

      frame = new MyFrame();
      frame.show();

When you run this applet, the NullPointerException error appears.

REFERENCES

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, see the following page on the Microsoft Technical Support site:

   http://support.microsoft.com/support/visualj/ 
   http://support.microsoft.com/support/java/ 

Additional query words: NullPointerException java

Keywords          : kbtool kbwizard kbGenInfo kbMFC kbVC kbVJ kbbuglist
Version           : 1.0 1.1
Platform          : WINDOWS
Issue type        : kbbug

Last Reviewed: February 1, 1998