title: Initialize NodeList Java
body: <p>I was trying to get rid of the null initialization of the NodeList, but it doesn't appear I can do:</p>
  
  <pre><code>NodeList compiledNodeLIst = new Nodelist();
  </code></pre>
  
  <p>When I try move it inside the try statement like so:</p>
  
  <pre><code>private NodeList compileToNodeList(String pattern, Document document){
              try{
                  NodeList compiledNodeList = (NodeList) xPath.compile("/*/UserList/User").evaluate(document, XPathConstants.NODESET);
  </code></pre>
  
  <p>My Return variable can't be resolved and if I move that into the try block my method errors with no return statement. Below is the full statement.</p>
  
  <pre><code>   private NodeList compileToNodeList(String pattern, Document document){
              NodeList compiledNodeList = null;
              try{
                  compiledNodeList = (NodeList) xPath.compile("/*/UserList/User").evaluate(document, XPathConstants.NODESET);
              } catch (XPathExpressionException e){
                  //TODO code for logging
                  e.printStackTrace();
              }
              return compiledNodeList;
  </code></pre>
  
  <p>This technically is working, but I was hoping to either get rid of the null or have an explanation of why this won't be possible.</p>