Search code examples
androidandroid-videoviewandroid-video-player

Can not access memory card on HTC ONE V


I am developing and testing a simple video player example in Android. Code is given below:

VideoView vid = (VideoView) findViewById(R.id.videoView1);

vid.setVideoPath("/sdcard/myvideo.mp4");
vid.setMediaController(new MediaController(this));
vid.start();
vid.requestFocus();

I am using HTC ONE V. When I run this on my phone I am getting a NullPointerException on the line where I set the path of video (i.e. setVideoPath("/sdcard/myvideo.mp4")). I think there is problem in accessing the memory card.

So can anyone kindly tell that is the way to access memory card on HTC ONE V different from other phones? And if yes then how to access the memory card HTC ONE V.


Solution

  • If you are getting NullpointerException on the line

    vid.setVideoPath("/sdcard/myvideo.mp4");
    

    then that indicates vid is null.

    So make sure setContentView is done in Oncreate before you call findviewbyid and make sure R.id.videoView1 is present in the Layout that you have set.

    As others have pointed do not hard code sdcard path.