How to use constructor parameter in initializing block
<p>I am using NetBeans IDE for swings programming</p>

<p>This is a Add/Edit scenario, <code>MyFrame1</code> handles <code>MyClass1</code> obj and <code>MyClass1</code> has <code>MyClass2</code>, if a <code>MyClass2</code> has to be add/edit present in <code>MyClass1</code>  <code>MyFrame1</code> launches <code>MyFrame2</code></p>

<p>I tried using the following code and got <code>NullPointerException</code></p>

<pre><code>class MyFrame2 extends JFrame implements ActionListener{
  MyFrame1 parent;
  MyClass2 obj;
  Test(MyFrame1 parent){ // For Add scenario
     //this.parent = parent
     obj = new MyClass2();
     //do something
  }
  Test(MyFrame1 parent, MyClass2 obj){ // For Edit scenario
     //this.parent = parent 
     this.obj = obj;
     //do something
  }
  //functions
  ........
  private void foo(){
     parent.addValues(obj); //throws NullPointerException
  }

  //some editor managed code and fields
  ............

  {
     this.parent = parent; 
     //other initalizations
  }
}
</code></pre>

<p>As far as I know the</p>

<ol>
<li><p>initializing block code is copied to the beginning of every constructor </p></li>
<li><p>initializing a field inside initializing block, the declaration of the field should present before the initializing block.</p></li>
</ol>

<p>Then why I am getting <code>NullPointerException</code> when I include <code>this.parent = parent;</code> in  initializing block and works fine if directly added to the constructors?</p>

<p>Is initializing block code not copied to the constructor?</p>