title: Null Pointer Exception findViewById of fragment item From Activity
body: <p>I'm new to Android, and I'm including a fragment in an Activity programmatically.</p>
  
  <p><strong>Here's my Fragment class Code :</strong> </p>
  
  <pre><code>import com.pt.app.R;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  public class MediaDisplayFragment extends Fragment {
  
      @Override
      public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          return inflater.inflate (R.layout.media_display_fragment, container, false);
      }
  }
  </code></pre>
  
  <p><strong>and my Activity's code :</strong></p>
  
  <pre><code>public class ReadMediasView extends FragmentActivity {
  
      @Override
      protected void onCreate (Bundle savedInstanceState) {
          super.onCreate (savedInstanceState);
  
          setContentView (R.layout.read_medias_view);
  
          Fragment            fragment            = new MediaDisplayFragment ();
          FragmentManager     fragmentManager     = getSupportFragmentManager();
          FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
          fragmentTransaction.replace (R.id.readMediaViewContainerContent, fragment);
  
          // Null Pointer Exception Here
          TextView text = (TextView)fragment.getView ().findViewById (R.id.mediaDisplayText);
          text.setVisibility (View.VISIBLE);             
      }
  }
  </code></pre>
  
  <p><strong>EDIT :</strong> And this is my My Logcat output : </p>
  
  <pre><code>FATAL EXCEPTION: main
  Process: com.pt.app, PID: 28492
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pt.app/com.pt.app.ReadMediasView}: java.lang.NullPointerException
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
  at android.app.ActivityThread.access$800(ActivityThread.java:135)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:136)
  at android.app.ActivityThread.main(ActivityThread.java:5017)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.NullPointerException
  at com.pt.app.ReadMediasView.onCreate(ReadMediasView.java:91)
  at android.app.Activity.performCreate(Activity.java:5231)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
  ... 11 more
  </code></pre>
  
  <p>Why do I get this NullPointerException ? Thank you.</p>