title: Android play video in surfaceview NullPointerException
body: <p>I try to play video in surfaceview. I use  Fragment (extends Fragment) and I have <code>NullPointerException</code>. I have no idea what am I doing wrong. First time I used Activity and in Activity  project worked perfect but I use Fragment and I have error</p>
  
  <p>This is a my source</p>
  
  <pre><code>public class Layout1 extends Fragment implements OnBufferingUpdateListener,
      OnCompletionListener, OnPreparedListener, OnVideoSizeChangedListener,
      SurfaceHolder.Callback, MediaPlayerControl {
  MediaPlayer mMediaPlayer;
  SurfaceView mSurfaceView;
  SurfaceHolder holder;
  String video = "http://www.pocketjourney.com/downloads/pj/video/famous.3gp";
  MediaController mcontroller;
  Handler handler;
  String videoUrl;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.fragment_layout1, null);
  
      SurfaceView v = (SurfaceView) view
              .findViewById(R.id.screen_tutorial_video_surface);
      handler = new Handler();
      holder = v.getHolder();
      holder.addCallback(this);
      playVideo();
      return view;
  }
  
  private void playVideo() {
      try {
          mcontroller = new MediaController(getActivity());
          mcontroller.setVisibility(View.INVISIBLE);
  
          mMediaPlayer = MediaPlayer.create(getActivity(), Uri.parse(video));
          mMediaPlayer.setOnBufferingUpdateListener(this);
          mMediaPlayer.setOnCompletionListener(this);
          mMediaPlayer.setOnPreparedListener(this);
  
          mMediaPlayer.setScreenOnWhilePlaying(true);
          mMediaPlayer.setOnVideoSizeChangedListener(this);
  
          mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
  
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  
  @Override
  public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
  
  }
  
  @Override
  public void surfaceCreated(SurfaceHolder arg0) {
  
      mMediaPlayer.setDisplay(holder);
      try {
          // progressDialog.dismiss();
          mMediaPlayer.start();
  
      } catch (IllegalStateException e) {
          e.printStackTrace();
      }
  }
  
  @Override
  public void surfaceDestroyed(SurfaceHolder arg0) {
  
  }
  
  @Override
  public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
      // TODO Auto-generated method stub
  }
  
  @Override
  public void onPrepared(MediaPlayer mp) {
  
      // mcontroller.setMediaPlayer(this);
      // mcontroller
      // .setAnchorView(findViewById(R.id.screen_tutorial_video_surface));
      // mcontroller.setEnabled(true);
      //
      // handler.post(new Runnable() {
      // public void run() {
      // mcontroller.show();
      // }
      // });
  }
  
  @Override
  public void onCompletion(MediaPlayer mp) {
  
  }
  
  @Override
  public void onBufferingUpdate(MediaPlayer mp, int percent) {
  
  }
  
  public void start() {
      mMediaPlayer.start();
  }
  
  public void pause() {
      mMediaPlayer.pause();
  }
  
  public int getDuration() {
      return mMediaPlayer.getDuration();
  }
  
  public int getCurrentPosition() {
      return mMediaPlayer.getCurrentPosition();
  }
  
  public void seekTo(int i) {
      mMediaPlayer.seekTo(1);
  }
  
  public boolean isPlaying() {
      return mMediaPlayer.isPlaying();
  }
  
  public int getBufferPercentage() {
      return 0;
  }
  
  public boolean canPause() {
      return true;
  }
  
  public boolean canSeekBackward() {
      return true;
  }
  
  public boolean canSeekForward() {
      return true;
  }
  }
  </code></pre>
  
  <p>Error log</p>
  
  <blockquote>
    <p><img src="https://i.stack.imgur.com/sX0C1.jpg" alt="enter image description here"></p>
  </blockquote>