title: Camera.setPreviewDisplay() throws Exception
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/7942378/android-camera-will-not-work-startpreview-fails">Android Camera will not work. startPreview fails</a>  </p>
  </blockquote>
  
  
  
  <p>I am trying to set a camera preview in a custom SurfaceView but I get an exception each time I execute the initialization method.</p>
  
  <p>Below is the code for camera preview initialization:</p>
  
  <pre><code>private void init(Context context)
  {
      setFocusable(true);
      mRecording = false;
      fileRW = new FileReaderWriter();
      frameCount = 0;
      if(mCamera == null)
      {
          mCamera = Camera.open();
      }
      Parameters parameters = mCamera.getParameters();
      parameters.setPictureFormat(PixelFormat.JPEG);
      mCamera.setParameters(parameters);
      try {
          mCamera.setPreviewDisplay(surfaceHolder);
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      mCamera.startPreview();
  
  }
  </code></pre>
  
  <p>the line <code>mCamera.setPreviewDisplay(surfaceHolder);</code> throws an exception (<code>setPreviewDisplay failed</code>) each time I try to execute the method.</p>
  
  <p>Does anyone know what could be wrong? I would really appreciate any of your help.</p>
  
  <p>Thanks!`</p>