title: NullPointerException when attempting to use VideoView in a fragment
body: <p>I am attempting to embed a YouTube video into my app, as described here: <a href="http://android-coffee.com/tutorial-how-to-play-youtube-videos-in-android-with-videoview/" rel="nofollow">http://android-coffee.com/tutorial-how-to-play-youtube-videos-in-android-with-videoview/</a></p>
  
  <p>However, I seem to be encountering a NullPointerException error when I access the fragment and I cannot seem to find the causation.</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.VideoView.setVideoURI(android.net.Uri)' on a null object reference
  </code></pre>
  
  <p>The code for the fragment is as follows.</p>
  
  <pre><code>import android.widget.MediaController;
  import android.net.Uri;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.VideoView;
  
  
  public class VideosFragment extends Fragment {
  
  
  public VideosFragment() {
      // Required empty public constructor
  }
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.fragment_compare, container, false);
      VideoView videoView;
      videoView = (VideoView)view.findViewById(R.id.videoView);
      MediaController mediaController;
      mediaController = new MediaController(view.getContext());
      mediaController.setAnchorView(videoView);
      Uri uri= Uri.parse("rtsp://r7---sn-4g57kue6.googlevideo.com/Ck0LENy73wIaRAmk3cJBg-iaXhMYDSANFC3u0pRWMOCoAUIJbXYtZ29vZ2xlSARSBXdhdGNoYIaluaTkzciOVooBCzVxRjNraG5XcXdnDA==/D693A8E7577C3A29E60C292B42C9C87D7C25A565.762A63DC4CA0A028DA83256C6A79E5F160CBEDA3/yt6/1/video.3gp");
      videoView.setMediaController(mediaController);
      videoView.setVideoURI(uri);
      videoView.requestFocus();
      videoView.start();
  
  
  
      return inflater.inflate(R.layout.fragment_videos, container, false);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here is the layout file:</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="com.[left out for security].VideosFragment"
  android:background="?android:attr/colorBackground"&gt;
  
  &lt;!-- TODO: Update blank fragment layout --&gt;
  
  &lt;VideoView
      android:id="@+id/videoView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerVertical="true"
      android:layout_centerHorizontal="true" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>Thanks for any help!</p>