Im having troubles inserting a java classes I wrote into my android application. As a standalone java application, it works fine. once I take the classes and put them inside my android app, I have an exception when trying to manipulate xml object. I use the following:
import org.w3c.dom.Element;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;
What I do is basically this:
Document doc;
Element root = GetRootElement("root");
Element nameElement;
nameElement = doc.createElement("x");
nameElement.setTextContent("y");
root.appendChild(nameElement);
DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
return lsSerializer.writeToString(doc); //sends the xml's string somewhere else in the code
Now, running this code as a regular java application works, but in an android app, it will fail in the doc.getImplementation()
line, with the following error:
Caused by: java.lang.ClassCastException: org.apache.harmony.xml.dom.DOMImplementationImpl cannot be cast to org.w3c.dom.ls.DOMImplementationLS
I tried to give as much as info as possible, I hope it helps.