title: Android Record video
body: <p>I have this problem with getting my adnroid program to work. I have this as my record.java code</p>
  
  <pre><code>import java.io.IOException;
  
  
  
  import android.app.Activity;
  import android.content.Intent;
  import android.content.pm.ActivityInfo;
  import android.media.CamcorderProfile;
  import android.media.MediaRecorder;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.MenuItem;
  import android.view.Surface;
  import android.view.SurfaceHolder;
  import android.view.SurfaceHolder.Callback;
  import android.view.SurfaceView;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Toast;
  
  public class record extends Activity{
  
      MediaRecorder recorder;
      SurfaceHolder holder;
      boolean recording = false;
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  
          recorder = new MediaRecorder();
          initRecorder();
          setContentView(R.layout.view);
  
          SurfaceView cameraView = (SurfaceView) findViewById(R.id.sView);
          holder = cameraView.getHolder();
          holder.addCallback((Callback) this);
          holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  
          cameraView.setClickable(true);
          cameraView.setOnClickListener((OnClickListener) this);
      }
  
      private void initRecorder() {
          recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
          recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
  
          CamcorderProfile cpHigh = CamcorderProfile
                  .get(CamcorderProfile.QUALITY_HIGH);
          recorder.setProfile(cpHigh);
          recorder.setOutputFile("/sdcard/videocapture_example.mpg");
          recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
          recorder.setMaxDuration(60000); // 60 seconds
          recorder.setMaxFileSize(100000000);// Approximately 10 megabytes
          recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
  
  
      }
  
  
      private void prepareRecorder() {
          recorder.setPreviewDisplay(holder.getSurface());
  
          try {
              recorder.prepare();
          } catch (IllegalStateException e) {
              e.printStackTrace();
              finish();
          } catch (IOException e) {
              e.printStackTrace();
              finish();
          }
      }
  
      public void onClick(View v) {
          if (recording) {
              recorder.stop();
              recording = false;
  
              // Let's initRecorder so we can record again
              initRecorder();
              prepareRecorder();
          } else {
              recording = true;
              recorder.start();
          }
      }
  
      public void surfaceCreated(SurfaceHolder holder) {
          prepareRecorder();
      }
  
      public void surfaceChanged(SurfaceHolder holder, int format, int width,
              int height) {
      }
  
      public void surfaceDestroyed(SurfaceHolder holder) {
          if (recording) {
              recorder.stop();
              recording = false;
          }
          recorder.release();
          finish();
  
      }
  </code></pre>
  
  <p>My android manifest looks like this as well</p>
  
  <p></p>
  
  <pre><code>        &lt;activity android:name=".record"
                android:label="@string/app_name"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.apapa.ttt.RECORD" /&gt;
  
          &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
  &lt;/application&gt;
  
  
  &lt;uses-sdk android:minSdkVersion="8" /&gt;
  &lt;uses-permission android:name="android.permission.CAMERA" /&gt;
  &lt;uses-permission android:name="android.permission.RECORD_VIDEO"/&gt;
  &lt;uses-feature android:name="android.hardware.camera"/&gt;
  &lt;uses-feature android:name="android.hardware.camera.autofocus"/&gt;
  &lt;uses-permission android:name="android.permission.record_audio"/&gt;
  </code></pre>
  
  <p> </p>
  
  <p>How ever, when I run this code it always brings up the error "The application has stopped unexpectedly. Please Try again" I'm really confused what I am doing wrong here because I think I have every step right. Any help will be much appreciated.</p>