title: NullPointerException while USB Device connection
body: <p>I try to connect with my custom USB Device. I've done everything step by step with android doc but I still get null pointer at connection object. Here's my activity:</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          PendingIntent mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
          IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
          registerReceiver(usbReceiver, filter);
  
      usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
      HashMap&lt;String, UsbDevice&gt; deviceList = usbManager.getDeviceList();
      Iterator&lt;UsbDevice&gt; deviceIterator = deviceList.values().iterator();
      while (deviceIterator.hasNext()) {
          UsbDevice device = deviceIterator.next();
  
          if (device.getVendorId() == 1659 &amp;&amp; device.getProductId() == 8963) {
              this.device = device;
              usbManager.requestPermission(device, mPermissionIntent);
              Toast.makeText(MainActivity.this, "vendor: " + device.getVendorId() + "ID " + device.getProductId() , Toast.LENGTH_SHORT).show();
              break;
          }
      }
  </code></pre>
  
  <p>And this is how I try to connect with USB device :</p>
  
  <pre><code>mTestButton = (Button) findViewById(R.id.button);
          mTestButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  usbInterface = device.getInterface(0);
                  if (connection != null) {
                      connection = usbManager.openDevice(device);
                      connection.claimInterface(usbInterface, false);
  
                  for (int i = 0; i &lt; usbInterface.getEndpointCount(); i++) {
                      UsbEndpoint end = usbInterface.getEndpoint(i);
                      if (end.getDirection() == UsbConstants.USB_DIR_IN) {
                          usbEndpointIn = end;
  
                      } else {
                          usbEndpointOut = end;
                      }
                  }
  
                  //SEND START COMMAND TO  THE USB DEVICE;
                  int result = connection.bulkTransfer(usbEndpointOut, "START".getBytes(), "START".getBytes().length, 1000);
                  Log.e("SEND RESULT", result + "");
  
  
                  //START READING in run method
                  readThread = new Thread((Runnable) MainActivity.this);
                  readThread.start();
  
              } else {
                  Toast.makeText(MainActivity.this, "Connection is null", Toast.LENGTH_SHORT).show();
              }
  </code></pre>
  
  <p>But connection is still null :/ Help, please.</p>