Unable to play video in video view in android
<p>I have an activity which plays video from an SD card but it throws a NullPointerException on the line: <code>myVideoView.getHolder().lockCanvas().rotate(90);</code></p>

<p><strong>Code:</strong></p>

<pre><code>public class CameraPlay extends Activity {

    public static String result = "";
    String root;
    ApplicationGlobalClass applicationGlobalClass;
    Button btn_Done, btn_Cancel;
    VideoView myVideoView;
    RantBackIdentityCollection rantBacks = RantBackIdentityCollection.getSigletonObject();
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);

       setContentView(R.layout.cameraplay);
       applicationGlobalClass=new ApplicationGlobalClass();
       root = Environment.getExternalStorageDirectory().toString();
       myVideoView = (VideoView)findViewById(R.id.myvideoview);
       btn_Done = (Button)findViewById(R.id.btn_CameraPlay_Done);
       btn_Cancel = (Button)findViewById(R.id.btn_CameraPlay_Cancel);

       ExifInterface exif=null;
    try {
        exif = new ExifInterface(root+"/myvideo.mp4");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }     //Since API Level 5
     /*  String exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
       myVideoView.setVideoPath(root+"/myvideo.mp4");
       myVideoView.setMediaController(new MediaController(this));
       myVideoView.requestFocus();
       myVideoView.start();*/
     MediaController mediaController = new MediaController(this);
     mediaController.setAnchorView(myVideoView);
     myVideoView.setMediaController(new MediaController(this));
     handler.sendEmptyMessage(1);



       btn_Done.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            if (applicationGlobalClass.getCategoryName().equals("REAL STATE")) {

               Intent myIntent=new Intent(CameraPlay.this,UploadRalStateCategory.class);
               startActivity(myIntent);
               finish();

            }
            else{
           Intent myIntent=new Intent(CameraPlay.this,UploadCategory.class);
           startActivity(myIntent);
          }
        }
    });
       btn_Cancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(CameraPlay.this, VideoCapture_New.class);
            startActivity(intent);
        }
    });

   }
   Handler handler = new Handler(){

       public void handleMessage(Message msg){

           int pos=msg.what;
           if (pos == 1){

               myVideoView.setVideoPath(root+"/myvideo.mp4");
               myVideoView.getHolder().lockCanvas().rotate(90); 
               myVideoView.requestFocus();
               myVideoView.start();

               Log.d("Before Video Finish", "i m in before video finish");
               myVideoView.setOnCompletionListener(new OnCompletionListener() {
                   @Override
                   public void onCompletion(MediaPlayer mp) {
                       finish();
                   }
               });
           }
       }
   };

   public void callDialog() {
        // TODO Auto-generated method stub
        new AlertDialog.Builder(this)
        .setMessage("Video Uploaded successfully") 
        .setNegativeButton("Ok",new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
               dialog.cancel();
               finish();
           }
       })
        .show();

    }
}
</code></pre>
