title: How to Sum String double Value
body: <p>I have a string like <code>24.5 km10.1 km30.9 km</code>. </p>
  
  <p>I want to compute the sum of all the distances in the string but I'm not able to do it. I'm getting a <code>NumberFormatException</code>.</p>
  
  <p>Here is my code</p>
  
  <pre><code>String stringValue = getDistanceOnRoad(lat, long, lat2, long2);
  double sumValue = 0.0;
  
  Log.d("my string is", stringValue);
  try {
      sumValue = Double.parseDouble(stringValue);
      Log.d("distance there plus", String.valueOf(sumValue));
  } catch (NumberFormatException e){
      System.out.println("not a number");
  }
  </code></pre>
  
  <p>I'm getting the distance from this method, everything is working fine but I'm not able to compute the sum of all distances.</p>
  
  <p><a href="https://stackoverflow.com/questions/6981916/how-to-calculate-distance-between-two-locations-using-their-longitude-and-latitu">How to calculate distance between two locations using their longitude and latitude value</a></p>
  
  <pre><code>private String getDistanceOnRoad(double latitude, double longitude,
          double prelatitute, double prelongitude) {
      String result_in_kms = "";
      String url = "http://maps.google.com/maps/api/directions/xml?origin="
              + latitude + "," + longitude + "&amp;destination=" + prelatitute
              + "," + prelongitude + "&amp;sensor=false&amp;units=metric";
      String tag[] = { "text" };
      HttpResponse response = null;
      try {
          HttpClient httpClient = new DefaultHttpClient();
          HttpContext localContext = new BasicHttpContext();
          HttpPost httpPost = new HttpPost(url);
          response = httpClient.execute(httpPost, localContext);
          InputStream is = response.getEntity().getContent();
          DocumentBuilder builder = DocumentBuilderFactory.newInstance()
                  .newDocumentBuilder();
          Document doc = builder.parse(is);
          if (doc != null) {
              NodeList nl;
              ArrayList args = new ArrayList();
              for (String s : tag) {
                  nl = doc.getElementsByTagName(s);
                  if (nl.getLength() &gt; 0) {
                      Node node = nl.item(nl.getLength() - 1);
                      args.add(node.getTextContent());
                  } else {
                      args.add(" - ");
                  }
              }
              result_in_kms = String.format("%s", args.get(0));
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
      return result_in_kms;
  }
  </code></pre>