title: Class throwing Null Pointer Exception
body: <p>Why does the following method throws an NPE,</p>
  
  <pre><code>public ActivityOne extends Activity{
     DataManager dtMan = new DataManager(this)
  
     public onCreate (){ 
      ...some source code here...
      dtMan.check();
     }
  }
  
  public class DataManager(){
     private Context myContext;
  
     public DataManager (Context context){
       myContext = context;
     }
  
     Helper helper = new Helper(this);
  
     public boolean check(){
       helper.open();
       ...some source code here...
     }
  }
  </code></pre>
  
  <p>When I view the logcat; I get a java.null.pointer exception, so I did something like</p>
  
  <pre><code>public class DataManager(){
     private Context myContext;
  
     public DataManager (Context context){
       myContext = context;
     }
  
     public boolean check(Context context){
       **Helper helper = new Helper(context);**
       helper.open();
       ...some source code here...
     }
  }
  </code></pre>
  
  <p>And it worked, so what is the difference between the two DataManager in Java/Android programming perspective, thus this approach if I understand correctly must be replicated to as follow:</p>
  
  <pre><code>public class DataManager(){
     private Context myContext;
  
     public DataManager (Context context){
       myContext = context;
     }
  
     public boolean check(Context context){
       **Helper helper = new Helper(context);**
       helper.open();
       ...some source code here...
     }
  
     public boolean check2(Context context){
       **Helper helper = new Helper(context);**
       helper.open();
       ...some source code here...
     }
  
     public boolean check3(Context context){
       **Helper helper = new Helper(context);**
       helper.open();
       ...some source code here...
     }
  }
  </code></pre>
  
  <p>Meaning I just can't declare the Helper Class once and use it anywhere the calling class, did I forgot some fundamentals? Please clarify.</p>
  
  <p>Will the context also lead to memory leaks?, if so, how will I fix it?</p>
  
  <p>@EDIT:</p>
  
  <p>Well I forgot to include the Helper Class</p>
  
  <p>public class Helper{
       private Context myContext;</p>
  
  <pre><code> public Helper(Context context){
      myContext = context;
   }
  
   public void open(){
    //do stuff here
   }
  </code></pre>
  
  <p>}</p>