title: Getting the activity inside fragment gives null pointer exception
body: <p>The problem is similar to <a href="https://stackoverflow.com/questions/11743272/android-fragment-cannot-get-activity">this</a> SO post.</p>
  
  <p>@Jason replies that -</p>
  
  <blockquote>
    <p>Your Fragment hasn't attached to the Activity yet, which also means
    your layout hasn't been inflated yet.</p>
  </blockquote>
  
  <p>In that case, the issue was to simply pass the string from one fragment to another.</p>
  
  <p>However, here I need to do something different:</p>
  
  <p><strong>Common.java</strong></p>
  
  <pre><code>public class Common extends Fragment
  {
     OnSelectedListener mCallback = new OnSelectedListener(){
       public void getFailureDialog(){
  
                  RecordFailure fd = new RecordFailure(); 
                  fd.show(getActivity().getSupportFragmentManager(), "dialog"); //Null pointer exception here.
  
          }
  };
  </code></pre>
  
  <p>I call <code>mCallback.getFailureDialog()</code> to call that method.</p>
  
  <p><strong>Error Log:</strong></p>
  
  <pre><code>03-22 18:21:30.022: E/AndroidRuntime(9385): java.lang.NullPointerException
  03-22 18:21:30.022: E/AndroidRuntime(9385):     at com.cornmain.util.Common$1.getFailureDialog(Common.java:112)
  </code></pre>
  
  <p>How to do that?</p>
  
  <p>UPDATE:</p>
  
  <p>If I use <code>fd.show(getFragmentManager(), "dialog");</code>, then I get the following error:</p>
  
  <p>Error Log:</p>
  
  <pre><code>03-22 18:35:18.432: E/AndroidRuntime(11872): java.lang.NullPointerException
  03-22 18:35:18.432: E/AndroidRuntime(11872):    at android.support.v4.app.DialogFragment.show(DialogFragment.java:125)
  03-22 18:35:18.432: E/AndroidRuntime(11872):    at com.cornmain.util.Common$1.getFailureDialog(Common.java:112)
  </code></pre>