title: Using intent to use Camera in Android
body: <p>I am using the following code to use camera by using intent.
  In the parameter of intent I am passing <code>android.provider.MediaStore.ACTION_IMAGE_CAPTURE</code>.
  It is able to open the camera.
  But the problem is that it stops unexpectedly.
  The problem is that it gives null pointer exception on <code>OnActivityResults</code>.
  I have used the below code:</p>
  
  <pre><code>public class demo extends Activity {
  
  Button ButtonClick;
  int CAMERA_PIC_REQUEST = 2; 
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      ButtonClick =(Button) findViewById(R.id.Camera);
      ButtonClick.setOnClickListener(new OnClickListener (){
          @Override
          public void onClick(View view)
          {
              Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
              // request code
  
              startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
  
          }
      });
  
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) 
  {
      if( requestCode == CAMERA_PIC_REQUEST)
      {
      //  data.getExtras()
          Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
          ImageView image =(ImageView) findViewById(R.id.PhotoCaptured);
          image.setImageBitmap(thumbnail);
      }
      else 
      {
          Toast.makeText(demo.this, "Picture NOt taken", Toast.LENGTH_LONG);
      }
      super.onActivityResult(requestCode, resultCode, data);
  }
  }
  </code></pre>
  
  <p>Can anyone help me to solve this problem?</p>