Microsoft KB Archive/167942

= BUG: NullPointerException in DialogLayout Constructor =

Article ID: 167942

Article Last Modified on 8/25/2005

-

APPLIES TO


 * Microsoft Visual J++ 1.0 Standard Edition
 * Microsoft Visual J++ 1.1 Standard Edition

-



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.



Steps to Reproduce Behavior
 Generate an Applet using VJ1.0/1.1 AppletWizard. Remove the multi-threaded option and leave everything else as default. Create a new Dialog resource named NewDialog with the default OK and Cancel buttons on it. Save it as a .rct file. Run Java Resource Wizard to create the corresponding .java files.  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; } }                         In the Applet class instantiate the frame class as: <pre class="fixed_text">  MyFrame frame = null; </li>  In the Applets init function call: <pre class="fixed_text">  frame = new MyFrame; frame.show; </li></ol>

When you run this applet, the NullPointerException error appears.

<div class="references_section">