title: getting null object reference in Bundle getExtras() method
body: <p>I am creating an app which captures image from camera and saves image in a file. In <strong>onActivityResult()</strong> method i am getting null object reference error.
  My Fragment class is here:</p>
  
  <pre><code>public class HomeFragment extends Fragment {
  private static final int REQUEST_IMAGE_CAPTURE = 1;
  private static final String JPEG_FILE_PREFIX = "IBR_";
  private static final String JPEG_FILE_SUFFIX = ".jpg";
  File photoFile = null;
  ImageButton camera_button;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
  
      View rootView = inflater.inflate(R.layout.fragment_home, container, false);
      camera_button = (ImageButton) rootView.findViewById(R.id.camera);
      camera_button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
              // Ensure that there's a camera activity to handle the intent
              if (cameraIntent.resolveActivity(getActivity().getPackageManager()) != null) {
                  // Create the File where the photo should go
                  try {
                      photoFile = createImageFile();
                  } catch (IOException ex) {
                      // Error occurred while creating the File
                      Log.i("File error", "File");
                  }
              }
              // Continue only if the File was successfully created
              if (photoFile != null) {
                  Uri fileUri = Uri.fromFile(photoFile);
                  cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
                          fileUri);
                  Toast.makeText(getActivity(), photoFile.toString(), Toast.LENGTH_SHORT).show();
                  startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE);
              }
          }
      });
  
      return rootView;
  }
  
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (requestCode == REQUEST_IMAGE_CAPTURE &amp;&amp; resultCode == Activity.RESULT_OK) {
          Bundle extras = data.getExtras();
          Bitmap imageBitmap = (Bitmap) extras.get("data");
          camera_button.setImageBitmap(imageBitmap);
      }
  
  }
  
  private File createImageFile() throws IOException {
      // Create an image file name
      String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
      String imageFileName = JPEG_FILE_PREFIX + timeStamp + "_";
      File storageDir = Environment.getExternalStoragePublicDirectory(
              Environment.DIRECTORY_PICTURES);
      File imageF = File.createTempFile(imageFileName, JPEG_FILE_SUFFIX, storageDir);
      return imageF;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Actually i am getting error in this line <strong>Bundle extras = data.getExtras();</strong> 
  Any suggestion how can i solve this problem?</p>