I included the camera permission in AndroiManifest.xml.
The below code doesn't show any error. The app opens normally. When I click the button the app crashes. Please help me.

package com.akdevil.camera;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

static final int REQUEST_IMAGE_CAPTURE = 1;
ImageView AkashImage;
protected void onCreate(Bundle savedInstanceState) {

//create a reference for button
Button AkashButton = (Button) findViewById(R.id.AkashButton);
//create a reference for ImageView
AkashImage = (ImageView) findViewById(R.id.AkashImage);

//disable the button if smartphone don’t have a camera in it
if (!hasCamera())


//Method to check the camera existence
private boolean hasCamera() {
return getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);

//Launching camera
public void launchCamera(View view) {

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//Take pic and pass results along to onActivityResult
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);


//to return the image taken

public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK){
//get the photo
Bundle extras = data.getExtras();
//converting to Bitmap
Bitmap photo = (Bitmap) extras.get("data");