title: null pointer exception on calling interface method implemented in other class
body: <p>I am trying to call the method <code>getFailureDialog()</code> of the interface <code>OnSelectedListener</code>.
  The method is implemented in <code>MainActivity.java</code>. But when I call the method, I am getting 
  the null pointer exception. </p>
  
  <p>I know that its because <code>OnSelectedListener</code> is still not initialized and you are calling <code>getFailureDialog()</code> on uninitialized object. Obviously, interface methods are never initialized. But then how do I call the method <code>getFailureDialog()</code> from my class <code>Common.java</code>?</p>
  
  <p>I am placing only the relevant source code below-</p>
  
  <p>Source code:</p>
  
  <p><strong>SharedFragment.java</strong></p>
  
  <pre><code>public class SharedFragment extends DialogFragment 
  {       
      Bundle bundle = getArguments();
      final String email = bundle.getString("email");
  
      Thread t=new Thread(new Runnable() 
      {
          public void run() {
          common.myRecord(email);
      }
      });   t.start(); 
  }
  </code></pre>
  
  <p><strong>Common.java</strong></p>
  
  <pre><code>public class Common
  {
  OnSelectedListener mCallback;
  
  
      public interface OnSelectedListener 
      {
          public void getFailureDialog();
      }
  
      public void myRecord(String email)
      {
          mCallback.getFailureDialog();  //null pointer exception here
      }
  }
  </code></pre>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity implements Common.OnSelectedListener
  {
  
  @Override
      public void getFailureDialog()
      {
  
          RecordFailure fd = new RecordFailure(); 
          fd.show(getSupportFragmentManager(), "dialog");
      }
  }
  </code></pre>
  
  <p><strong>Error Log</strong></p>
  
  <pre><code>03-22 15:50:39.032: W/dalvikvm(20796): threadid=16: thread exiting with uncaught exception (group=0x4204c450)
  03-22 15:50:39.052: E/AndroidRuntime(20796): FATAL EXCEPTION: Thread-30126
  03-22 15:50:39.052: E/AndroidRuntime(20796): java.lang.NullPointerException
  03-22 15:50:39.052: E/AndroidRuntime(20796):    at com.cornmail.util.Common.myRecord(Common.java:2062)
  </code></pre>