title: Future get() gets nullpointer exeception in java
body: <p>I'm implementing a function that detects if there is a webcam. This piece of code works fine in windows and I had no problem with it in linux centos OS. Now I'm trying to run the same code in Ubuntu, here an exception is thrown.</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
  at CameraProperties.CheckForCameraPlugin.check(CheckForCameraPlugin.java:51)
  at Main.Main.main(Main.java:39)
  </code></pre>
  
  <p>The code is given below.</p>
  
  <pre><code>public boolean check() 
  { 
      boolean b = true;
      service = Executors.newFixedThreadPool(1);
      task = service.submit(new InitialCameraChecker());
      try 
      {
          final String str;
          // waits the 10 seconds for the Callable.call to finish.
          str = task.get();
          if (str.matches("nodevice"))
          {
              b = false;//Return false if no camera device found
          } 
          else 
          {
              b = true;
          }
  
      } 
      catch (InterruptedException | ExecutionException ex) 
      {            
          msgbox.showJoptionPane(15);
      }
      service.shutdownNow();
      return b;
  }
  </code></pre>
  
  <p>The callable class is given below</p>
  
  <pre><code>class InitialCameraChecker implements Callable&lt;String&gt;
  {
  private List&lt;Integer&gt; devices = new ArrayList&lt;Integer&gt;();
  private final static String VERSION_ID = "1.0.0";
  private String res;
  
  //Checking for the Camera 
  public String call() 
  {
      try 
      {
          loadWebcam();
          discoverDevices();
          if (devices.isEmpty()) 
          {                
              res = "nodevice";//No we cam device found
          } 
          else 
          {                
              res = "founddevice";//Found Web Cam Device
          }
      } 
      catch (Exception ex) 
      {
          System.out.println("Exception_logout" + ex.toString());
      }
      return res;
  }
  
  
  //Discovering the camera device
  private void discoverDevices() 
  {
      for (int i = 0; i &lt; 10; i++)
      {
          CvCapture cap = null;
          try 
          {
              cap = cvCreateCameraCapture(i);
              int res = cvGrabFrame(cap);
              if (res &gt; 0) 
              {
                  devices.add(i);                    
                  break;
              }
          } 
          catch (Exception e) 
          {
              System.out.println("Exception in camaracheck Thread1");
          } 
          finally 
          {
              if (cap != null) 
              {
                  try 
                  {
                      cvReleaseCapture(cap.pointerByReference());
                  } 
                  catch (Exception e) 
                  {
                      e.printStackTrace();
                  }
              }
          }
      }
  }
  
  
  //Loading the dlls for starting the camera
  private void loadWebcam() 
  {    
      String tmpDir = System.getProperty("java.io.tmpdir");        
      File faPath = new File(tmpDir + File.separator + "WebcamApplet_" + VERSION_ID.replaceAll("\\.", "-"));        
      System.setProperty("jna.library.path", faPath.getAbsolutePath());
  }
  }
  </code></pre>
  
  <p>Please tell me what is the problem. This works fine in windows.</p>