title: Breadth First Search - Nullpointer Exception
body: <p>I have implement a breadth first search for a school project where i get the start-node of a directional graph as an input and i have to return a Linked List containing the nodes in BFS order</p>
  
  <p>This is my approach:</p>
  
  <pre><code>public List&lt;Node&gt; breadthFirstSearch(Node startNode){
  
      //node list that has to be returned  
      LinkedList&lt;Node&gt; nodeList = new LinkedList&lt;Node&gt;();
  
      resetState();
  
      // TODO
  
      //Queueu for the DfS Algorithm 
      Queue&lt;Node&gt; nodeQueue = new LinkedList&lt;Node&gt;();
  
      //Add start node to NodeList and Queue
      nodeQueue.add(startNode);
      nodeList.add(startNode);
  
      //While the Queue isn't empty
      while(!nodeQueue.isEmpty()) {
          Node v = nodeQueue.poll();
          //iterate over adjacent nodes of current node and add them to Queue and List 
          for (Node w : getAdjacentNodes(v)) {
              //don't add if already traversed node
              if (!nodeList.contains(w)) {
                  nodeList.add(w);
                  nodeQueue.add(w);
              }
          }
      }
  
      return nodeList;
  }
  </code></pre>
  
  <p>I have tested my function for several graphs and I didn't get any errors at my own tests. But when I upload my code to the schools servers and they run their tests i get following error: <code>java.lang.NullPointerException in SearchTestng.testBFSCliqueNodes(SearchTestng.java:512)
  </code>
  I have been trying to reproduce the problem for hours now and none of my tutors seems to have an idea what could be causing the exception.</p>
  
  <p>Does any of you have an idea what could possibly cause a null pointer exception here ?</p>