title: Caused by: java.lang.reflect.InvocationTargetException
body: <p>I am using this tutorial:</p>
  
  <p><a href="http://www.vogella.com/articles/AndroidCamera/article.html" rel="nofollow">http://www.vogella.com/articles/AndroidCamera/article.html</a></p>
  
  <p>To <strong>capture an image and save it on SD Card</strong>, but whenever i run this program, getting : <strong>Unfortunately App has Stopped</strong></p>
  
  <p><strong>Error says:</strong>   </p>
  
  <p><em>Caused by: java.lang.reflect.InvocationTargetException</em></p>
  
  <p><strong>Line Number 39 is:</strong></p>
  
  <p>camera.takePicture(null, null,
          new PhotoHandler(getApplicationContext()));</p>
  
  <p><strong>Logcat output:</strong></p>
  
  <pre><code>05-29 16:19:38.351: E/AndroidRuntime(767): FATAL EXCEPTION: main
  05-29 16:19:38.351: E/AndroidRuntime(767): java.lang.IllegalStateException: Could not execute method of the activity
  05-29 16:19:38.351: E/AndroidRuntime(767):  at android.view.View$1.onClick(View.java:3599)
  05-29 16:19:38.351: E/AndroidRuntime(767):  at android.view.View.performClick(View.java:4204)
  05-29 16:19:38.351: E/AndroidRuntime(767):  at android.view.View$PerformClick.run(View.java:17355)
  05-29 16:19:38.351: E/AndroidRuntime(767):  at android.os.Handler.handleCallback(Handler.java:725)
  05-29 16:19:38.351: E/AndroidRuntime(767):  at android.os.Handler.dispatchMessage(Handler.java:92)
  05-29 16:19:38.351: E/AndroidRuntime(767):  at android.os.Looper.loop(Looper.java:137)
  05-29 16:19:38.351: E/AndroidRuntime(767):  at android.app.ActivityThread.main(ActivityThread.java:5041)
  05-29 16:19:38.351: E/AndroidRuntime(767):  at java.lang.reflect.Method.invokeNative(Native Method)
  05-29 16:19:38.351: E/AndroidRuntime(767):  at java.lang.reflect.Method.invoke(Method.java:511)
  05-29 16:19:38.351: E/AndroidRuntime(767):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  05-29 16:19:38.351: E/AndroidRuntime(767):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  05-29 16:19:38.351: E/AndroidRuntime(767):  at dalvik.system.NativeStart.main(Native Method)
  05-29 16:19:38.351: E/AndroidRuntime(767): Caused by: java.lang.reflect.InvocationTargetException
  05-29 16:19:38.351: E/AndroidRuntime(767):  at java.lang.reflect.Method.invokeNative(Native Method)
  05-29 16:19:38.351: E/AndroidRuntime(767):  at java.lang.reflect.Method.invoke(Method.java:511)
  05-29 16:19:38.351: E/AndroidRuntime(767):  at android.view.View$1.onClick(View.java:3594)
  05-29 16:19:38.351: E/AndroidRuntime(767):  ... 11 more
  05-29 16:19:38.351: E/AndroidRuntime(767): Caused by: java.lang.NullPointerException
  05-29 16:19:38.351: E/AndroidRuntime(767):  at com.example.cameraapp.MakePhotoActivity.onClick(MakePhotoActivity.java:39)
  05-29 16:19:38.351: E/AndroidRuntime(767):  ... 14 more
  </code></pre>
  
  <p><strong>MakePhotoActivity.java:</strong></p>
  
  <pre><code>  public class MakePhotoActivity extends Activity {
    final static String DEBUG_TAG = "MakePhotoActivity";
    private Camera camera;
    private int cameraId = 0;
  
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      // do we have a camera?
      if (!getPackageManager()
          .hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        Toast.makeText(this, "No camera on this device", Toast.LENGTH_LONG)
            .show();
      } else {
        cameraId = findFrontFacingCamera();
        if (cameraId &lt; 0) {
          Toast.makeText(this, "No front facing camera found.",
              Toast.LENGTH_LONG).show();
        } else {
          camera = Camera.open(cameraId);
        }
      }
    }
  
    public void onClick(View view) {
      camera.takePicture(null, null,
          new PhotoHandler(getApplicationContext()));
    }
  
    private int findFrontFacingCamera() {
      int cameraId = -1;
      // Search for the front facing camera
      int numberOfCameras = Camera.getNumberOfCameras();
      for (int i = 0; i &lt; numberOfCameras; i++) {
        CameraInfo info = new CameraInfo();
        Camera.getCameraInfo(i, info);
        if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
          Log.d(DEBUG_TAG, "Camera found");
          cameraId = i;
          break;
        }
      }
      return cameraId;
    }
  
    @Override
    protected void onPause() {
      if (camera != null) {
        camera.release();
        camera = null;
      }
      super.onPause();
    }
  </code></pre>