title: camera app not working?
body: <p>I got following stack trace</p>
  
  <pre><code>04-17 12:11:56.378: D/ATRecorder(10379): com.htc.autotest.dlib.RecordEngine in loader dalvik.system.DexClassLoader@40528b78
  04-17 12:11:56.408: D/WindowManagerImpl(10379): addView, new view, mViews[0]: com.android.internal.policy.impl.PhoneWindow$DecorView@40520738
  04-17 12:11:56.428: D/WindowManagerImpl(10379): addView, new view, mViews[1]: android.widget.LinearLayout@40525d00
  04-17 12:11:56.438: D/WindowManagerImpl(10379): finishRemoveViewLocked, mViews[1]: android.widget.LinearLayout@40525d00
  04-17 12:11:56.718: D/TAG(10379): Error setting camera preview: setPreviewDisplay failed
  04-17 12:11:56.748: D/TAG(10379): Error starting camera preview: setPreviewDisplay failed
  04-17 12:12:07.558: D/View(10379): onTouchEvent: viewFlags: 0x18004001
  04-17 12:12:07.568: D/View(10379): onTouchEvent: isFocusable: true, isFocusableInTouchMode: false, isFocused: false; focusTaken: false
  04-17 12:12:07.588: V/MediaRecorderJNI(10379): start
  04-17 12:12:07.598: V/MediaRecorderJNI(10379): getMediaRecorder E
  04-17 12:12:11.632: V/MediaRecorderJNI(10379): process_media_recorder_call
  04-17 12:12:11.642: W/IMediaDeathNotifier(10379): media server died
  04-17 12:12:11.642: V/MediaRecorderJNI(10379): JNIMediaRecorderListener::notify
  04-17 12:12:11.642: V/MediaRecorderJNI(10379): notify msgType 0x1, ext1 0x64
  04-17 12:12:11.642: W/Camera(10379): ICamera died
  04-17 12:12:11.642: W/Camera(10379): Camera server died!
  04-17 12:12:11.702: E/Camera(10379): Error 100
  </code></pre>
  
  <p>and my code is</p>
  
  <pre><code>public class VideoDemoActivity extends Activity {
  /** Called when the activity is first created. */
  
  private Camera mCamera;
  private CameraPreview mPreview;
  private Button btnCapture,btnStop;
  
  private MediaRecorder mMediaRecorder;
  FrameLayout preview;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      initialize();
  
      if (!checkCameraHardware(this)) {
  
          Toast.makeText(this, "Camera not found", Toast.LENGTH_SHORT).show();
          finish();
  
      } else {
  
          Toast.makeText(this, "Camera found", Toast.LENGTH_SHORT).show();
      }
  
      mCamera = getCameraInstance();
      mPreview = new CameraPreview(this, mCamera);
      preview.addView(mPreview);
  
      System.out.println(prepareVideoRecorder());
  
  
      btnCapture.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              try {
  
                  mMediaRecorder.start();
              } catch (IllegalStateException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
          }
  
      });
  
      btnStop.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              mMediaRecorder.stop();
          }
      });
  
  }
  
  private void initialize() {
      // TODO Auto-generated method stub
  
      preview = (FrameLayout) findViewById(R.id.camera_preview);
      btnCapture = (Button) findViewById(R.id.button_capture);
      btnStop = (Button) findViewById(R.id.button_stop);
  }
  
  public Camera getCameraInstance(){
      Camera c = null;
      try {
          c = Camera.open(); // attempt to get a Camera instance
      }
      catch (Exception e){
  
          e.printStackTrace();
  
      }
      return c; // returns null if camera is unavailable
  }
  
  private boolean checkCameraHardware(Context context) {
      if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){
          // this device has a camera
          return true;
      } else {
          // no camera on this device
          return false;
      }
  }
  
  @Override
  protected void onPause() {
      // TODO Auto-generated method stub
      super.onPause();
  
       releaseMediaRecorder();       // if you are using MediaRecorder, release it first
       releaseCamera();              // release the camera immediately on pause event
  
  }
  
  private boolean prepareVideoRecorder(){
  
  
      mMediaRecorder = new MediaRecorder();
  
  
      mCamera.unlock();
      mMediaRecorder.setCamera(mCamera);
  
      mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
      mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
      mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
      mMediaRecorder.setOutputFile(getOutputMediaFile().toString());
  
  
  
      try 
      {
          mMediaRecorder.prepare();
  
      } catch (IllegalStateException e) {
          e.printStackTrace();
          releaseMediaRecorder();
          return false;
      } catch (IOException e) {
          e.printStackTrace();
          releaseMediaRecorder();
          return false;
      }
      return true;
  }
  
  private void releaseMediaRecorder(){
      if (mMediaRecorder != null) {
          mMediaRecorder.reset();   // clear recorder configuration
          mMediaRecorder.release(); // release the recorder object
          mMediaRecorder = null;
          mCamera.lock();           // lock camera for later use
      }
  }
  
  private void releaseCamera(){
      if (mCamera != null){
          mCamera.release();        // release the camera for other applications
          mCamera = null;
      }
  }
  
  private static File getOutputMediaFile(){
  
       File mediaFile = new File(Environment.getExternalStorageDirectory()+"/video.mp4");
  
      return mediaFile;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>So please help me in solving this problem.. If I remove the method</p>
  
  <blockquote>
    <p>prepareVideoRecorder()</p>
  </blockquote>
  
  <p>then it previews the camera properly.. but after this method execution it does not show any preview..and it fails </p>
  
  <blockquote>
    <p>mMediaRecorder.start();</p>
  </blockquote>
  
  <p>pleas help me out..</p>