title: Android camera showing black screen
body: <p>I'm trying to create a basic camera based Android app. I've covered the basics, SurfaceView + SurfaceHolder implementation in an activity designed to have a fullscreen SurfaceView. In surfaceCreated I am calling camera = Camera.open() in a try catch, with no exceptions being thrown during runtime. I have an ImageView set over the SurfaceView with an onClick function, basically acting as my "take picture" button. All of this works fine, except the only thing I see when I load the surface view activity is a black screen with the ImageView in the proper position. Then, when I perform a click on the ImageView, the app crashes and the attached logcat error appears. The stacktrace points to the line in my imageView's onClick</p>
  
  <blockquote>
    <p>camera.takePicture(...) </p>
  </blockquote>
  
  <p>Any ideas on why the image preview is black and the takePicture function is failing?
  Thanks!</p>
  
  <p><strong>LogCat</strong></p>
  
  <pre><code>03-02 17:22:29.002: E/AndroidRuntime(24787): FATAL EXCEPTION: main
  03-02 17:22:29.002: E/AndroidRuntime(24787): java.lang.RuntimeException: takePicture     failed
  03-02 17:22:29.002: E/AndroidRuntime(24787):    at     android.hardware.Camera.native_takePicture(Native Method)
  03-02 17:22:29.002: E/AndroidRuntime(24787):    at  android.hardware.Camera.takePicture(Camera.java:1194)
  03-02 17:22:29.002: E/AndroidRuntime(24787):    at    android.hardware.Camera.takePicture(Camera.java:1139)
  03-02 17:22:29.002: E/AndroidRuntime(24787):    at charles.michaels.getinsideyourface.CaptureActivity$4.onClick(CaptureActivity.java:58)
  03-02 17:22:29.002: E/AndroidRuntime(24787):    at android.view.View.performClick(View.java:4489)
  03-02 17:22:29.002: E/AndroidRuntime(24787):    at android.view.View$PerformClick.run(View.java:18803)
  03-02 17:22:29.002: E/AndroidRuntime(24787):    at android.os.Handler.handleCallback(Handler.java:730)
  03-02 17:22:29.002: E/AndroidRuntime(24787):    at android.os.Handler.dispatchMessage(Handler.java:92)
  03-02 17:22:29.002: E/AndroidRuntime(24787):    at android.os.Looper.loop(Looper.java:137)
  03-02 17:22:29.002: E/AndroidRuntime(24787):    at android.app.ActivityThread.main(ActivityThread.java:5455)
  03-02 17:22:29.002: E/AndroidRuntime(24787):    at java.lang.reflect.Method.invokeNative(Native Method)
  03-02 17:22:29.002: E/AndroidRuntime(24787):    at java.lang.reflect.Method.invoke(Method.java:525)
  03-02 17:22:29.002: E/AndroidRuntime(24787):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
  03-02 17:22:29.002: E/AndroidRuntime(24787):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
  03-02 17:22:29.002: E/AndroidRuntime(24787):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p><strong>surfaceHolder overrides</strong></p>
  
  <pre><code>public void surfaceCreated(SurfaceHolder holder)
  {
      Log.e(TAG, "surfaceCreated");
      try{
          camera = Camera.open();
          Log.d(TAG,"You opened that camera yo");
      }
      catch(Exception e){
          Log.e(TAG,e.toString());
      }
  }
  
  public void surfaceChanged(SurfaceHolder holder, int format, int w, int h)
  {
      Log.e(TAG, "surfaceChanged");
      try
      {
          if (previewRunning) {
              camera.stopPreview();
          }
  
          Camera.Parameters p = camera.getParameters();
          p.setPreviewSize(w, h);
          camera.setParameters(p);
          camera.setPreviewDisplay(holder);
          camera.startPreview();
          previewRunning = true;
      }
      catch(Exception e)
      {
          Log.d(TAG,e.toString());
      }
  }
  
  public void surfaceDestroyed(SurfaceHolder holder)
  {
      Log.e(TAG, "surfaceDestroyed");
      camera.stopPreview();
      previewRunning = false;
      camera.release();
      camera=null;
  }
  </code></pre>
  
  <p><strong>onClick function</strong></p>
  
  <pre><code>    iv.setOnClickListener(new OnClickListener(){
          public void onClick(View view){         
              {
  
                  camera.takePicture(mShutterCallback, mPictureCallback,mjpeg);
              }
          }
  
      });    
  </code></pre>