title: Android parse XML
body: <pre><code>public boolean editXML(String newCar) {
      try {
          String myXMLfile = "res\\values\\cars.xml";
  
          DocumentBuilderFactory docFactory = DocumentBuilderFactory
                  .newInstance();
          DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
          Document doc = docBuilder.parse(myXMLfile);
  
          Node string_array = doc.getElementsByTagName("string-array")
                  .item(0);
  
          Element item = doc.createElement("item");
          item.setTextContent(newCar);
          string_array.appendChild(item);
  
          TransformerFactory transformerFactory = TransformerFactory.newInstance();
          Transformer transformer = transformerFactory.newTransformer();
          DOMSource source = new DOMSource(doc);
          StreamResult result = new StreamResult(new File(myXMLfile));
          transformer.transform(source, result);
          return true;
      } catch (Exception e) {
          return false;
      }
  }
  </code></pre>
  
  <p>If I run a normal JAVA project, the function above works fine, but, if I run it in an android project it return false. Where is the problem? How to preview the e.printstacktrace in an android project so I can see what the exception says?</p>