BUG: NullPointerException in DialogLayout Constructor (167942)



The information in this article applies to:

  • Microsoft Visual J++ 1.0
  • Microsoft Visual J++ 1.1

This article was previously published under Q167942

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 pages on the Microsoft Technical Support site:

Modification Type:MinorLast Reviewed:8/25/2005
Keywords:kbArtTypeINF kbbug kbwizard KB167942