title: ZXing barcode scanner library giving camera error in Android 6.0 devices
body: <p>I have integrated ZXing barcode scanner library in my app.And I am handling the request permission dialogs for Android 6.0 devices.But my issue is when I am selecting 'Deny' in the request permission dialog am getting an  error like below image.If I click on 'Allow' app is working fine.Can anyone help me.I am scratching my head for a long time to solve this issue.Thanks in advance.[<img src="https://i.stack.imgur.com/MP8Pi.png" alt="enter image description here"><a href="https://i.stack.imgur.com/Txl7V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Txl7V.png" alt="][1]"></a></p>
  
  <p>The below is my code snippet in which I am handling the permission request for Marshmallow.</p>
  
  <pre><code>if (version &gt;= android.os.Build.VERSION_CODES.M) {
                  if (ContextCompat.checkSelfPermission(context,
                          Manifest.permission.CAMERA)
                          != PackageManager.PERMISSION_GRANTED) {
                      if (ActivityCompat.shouldShowRequestPermissionRationale(SearchActivity.this,
                              Manifest.permission.CAMERA)) {
  
                          ActivityCompat.requestPermissions(SearchActivity.this,
                                  new String[]{Manifest.permission.CAMERA},
                                  MY_PERMISSIONS_REQUEST_CAMERA);
  
                      } else {
  
                          // No explanation needed, we can request the permission.
  
                          ActivityCompat.requestPermissions(SearchActivity.this,
                                  new String[]{Manifest.permission.CAMERA},
                                  MY_PERMISSIONS_REQUEST_CAMERA);
  
  
                      }
                  }
              }
  
  @Override
  public void onRequestPermissionsResult(int requestCode,
                                         String permissions[], int[] grantResults) {
      switch (requestCode) {
          case MY_PERMISSIONS_REQUEST_CAMERA: {
              // If request is cancelled, the result arrays are empty.
              if (grantResults.length &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                  int version3 = Build.VERSION.SDK_INT;
                  // permission was granted, yay! Do the
                  // contacts-related task you need to do.
                  Toast.makeText(SearchActivity.this, "Permission granted", Toast.LENGTH_SHORT).show();
              } else {
  
                   Toast.makeText(SearchActivity.this, "Camera is required",    Toast.LENGTH_SHORT).show();
              }
              return;
          }
      }
  }
  </code></pre>
  
  <p>And the below is my error log.</p>
  
  <pre><code>08-23 10:49:07.894   9832-10612/com.test.xxx E/CameraInstance﹕ Failed to open camera
  java.lang.RuntimeException: Fail to connect to camera service
          at android.hardware.Camera.&lt;init&gt;(Camera.java:511)
          at android.hardware.Camera.open(Camera.java:353)
          at com.google.zxing.client.android.camera.open.OpenCameraInterface.open(OpenCameraInterface.java:83)
          at com.journeyapps.barcodescanner.camera.CameraManager.open(CameraManager.java:121)
          at com.journeyapps.barcodescanner.camera.CameraInstance$3.run(CameraInstance.java:158)
          at android.os.Handler.handleCallback(Handler.java:746)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:148)
          at android.os.HandlerThread.run(HandlerThread.java:61)
  
  08-23 10:49:09.268   9832-10668/com.test.ecommercetrial E/CameraInstance﹕ Failed to configure camera
  java.lang.NullPointerException: Attempt to invoke virtual method 'android.hardware.Camera$Parameters android.hardware.Camera.getParameters()' on a null object reference
          at com.journeyapps.barcodescanner.camera.CameraManager.setParameters(CameraManager.java:353)
          at com.journeyapps.barcodescanner.camera.CameraManager.configure(CameraManager.java:139)
          at com.journeyapps.barcodescanner.camera.CameraInstance$4.run(CameraInstance.java:171)
          at android.os.Handler.handleCallback(Handler.java:746)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:148)
          at android.os.HandlerThread.run(HandlerThread.java:61)
  </code></pre>