title: Java - Null Pointer Exception while parsing XML file
body: <p>I'm trying to parse an XML file of employees, and with the data in the XML I want to create an array list of all of the employees, but when I run the program and try to parse the XML file, it gives me a Null Point Exception. This is my XML file:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;employees&gt;
      &lt;employee&gt;
          &lt;name&gt;Roberta Robertson&lt;/name&gt;
          &lt;manager&gt;false&lt;/manager&gt;
      &lt;/employee&gt;
      &lt;employee&gt;
          &lt;name&gt;Taylor Meyers&lt;/name&gt;
          &lt;manager&gt;true&lt;/manager&gt;
      &lt;/employee&gt;
      &lt;employee&gt;
          &lt;name&gt;John Mayer&lt;/name&gt;
          &lt;manager&gt;true&lt;/manager&gt;
      &lt;/employee&gt;
  &lt;/employees&gt;
  </code></pre>
  
  <p>This is my code for parsing the XML file. I call the method when I press a certain button in my GUI.</p>
  
  <pre><code>public class employeesParser {
  private DocumentBuilder builder;
  private XPath path;
  
  private void employeesParser()
          throws ParserConfigurationException
  {
  
      // create the documentbuiler and path
      DocumentBuilderFactory dbfactory 
                  = DocumentBuilderFactory.newInstance();
      builder = dbfactory.newDocumentBuilder();
      XPathFactory xpfactory = XPathFactory.newInstance();
      path = xpfactory.newXPath();
  }
  
  // read the file
  public ArrayList&lt;Employee&gt; loadEmployees(String fileName)
      throws SAXException, IOException, XPathExpressionException
  {
      //parsing the file
  
      File f = new File(fileName);
      Document doc = builder.parse(f);
  
      //reading the file, extracting the employees, add employees to ArrayList
      int employeeCount = Integer.parseInt(path.evaluate(
          "count(/employees/employee)", doc));
  
      for (int i = 1; i &lt;= employeeCount; i++)
      {
          String employeeName = path.evaluate(
          "/employees/employee[" + i + "]/name", doc);
          boolean managerStatus = Boolean.parseBoolean(path.evaluate(
                  "employees/employee[" + i + "]/manager", doc));
          Employee employee = new Employee(employeeName, managerStatus);
          employeeList.add(employee);
      }
  
      return employeeList;
  
      }
  }
  </code></pre>
  
  <p>This is where I call the method:</p>
  
  <pre><code>private void addEmployeeXMLActionPerformed(java.awt.event.ActionEvent evt) {                                               
      // TODO add your handling code here:
      try {
          employeesParser parser = new employeesParser();
          employeeList = parser.loadEmployees("employees.xml");
      }
      catch (SAXException|IOException|XPathExpressionException e) {
      }
  }            
  </code></pre>
  
  <p>According to the exception message, the error occurs at this line of code:</p>
  
  <pre><code>    Document doc = builder.parse(f);
  </code></pre>
  
  <p>which is found in my loadEmployees() method. Can anyone tell me what I'm doing wrong? I've used code very similar to this before and it has worked. Thanks a lot!</p>