title: Parsing xml in eclipse
body: <p>I'm writing code in java and trying to parse the xml from this URL:
  <a href="https://maps.googleapis.com/maps/api/directions/xml?origin=30.606595,33.546753&amp;destination=30.657406,33.712234&amp;sensor=false" rel="nofollow">https://maps.googleapis.com/maps/api/directions/xml?origin=30.606595,33.546753&amp;destination=30.657406,33.712234&amp;sensor=false</a></p>
  
  <p>This URL is belong to google API, which takes 2 points (src, dest) and return the route between them in xml.</p>
  
  <p>When i debug the program with eclipse, it runs perfect. but when i run the code without debug, it returns an error. (when I put a breakpoint at the end of the function, the "dist" is null and i don't know why)
  Any idea why it happens?</p>
  
  <p>the code is</p>
  
  <pre><code>public double calcDist(Point p) //p=the src of the ride (the dest in the calculation)
      {
          String src = Double.toString(this.lati);
          src = src.concat(",");
          src = src.concat(Double.toString(this.longi));
          String dest = Double.toString(p.lati);
          dest = dest.concat(",");
          dest = dest.concat(Double.toString(p.longi));
  
      String dist=null;
      URL url = null;
      try 
      {
          url = new URL("https://maps.googleapis.com/maps/api/directions/xml?origin="+src+"&amp;destination="+dest+"&amp;sensor=false");
  
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
          DocumentBuilder db = null;
          db = dbf.newDocumentBuilder();
  
          Document doc = null;
          doc = db.parse(new InputSource(url.openStream()));
  
          doc.getDocumentElement().normalize();
          NodeList nodeList = doc.getElementsByTagName("leg");
  
          for (int i = 0; i &lt; nodeList.getLength(); i++) 
          {
              Node node = nodeList.item(i);
              NodeList nodeList2 =node.getChildNodes();
              for (int j = 0; j &lt; nodeList2.getLength(); j++) 
              {
                  Node child = nodeList2.item(j);
                  if (child.getNodeName().contentEquals("distance"))
                  {
                      NodeList nodeList3 = child.getChildNodes();
                      for (int p1 = 0; p1 &lt; nodeList3.getLength(); p1++) 
                      {
                          Node child2 = nodeList3.item(p1);
                          if (child2.getNodeName().contentEquals("text"))
                          {
                              Node tmp = child2.getFirstChild();
                              if (tmp != null) 
                                  dist = child2.getFirstChild().getNodeValue();
                          }
                      }
                  }
              }
          }
      }
      catch (ParserConfigurationException e) 
      {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      catch (SAXException e) 
      {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } 
      catch (IOException e) 
      {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      dist = dist.substring(0, dist.length()-3);
      return Double.parseDouble(dist);
  }
  </code></pre>