This discussion is archived
1 Reply Latest reply: May 13, 2012 12:08 AM by 936965 RSS

java.lang.AbstractMethodError: gnu.xml.dom.DomDocument.getXmlStandalone()Z

936965 Newbie
Currently Being Moderated
Good day,

I am writing a simple piece of code that is supposed to accomplish the following task; create an XML document from a thread. Here is the basic idea behind the application:

A starting desktop application (which is swing based) and loads all the information correctly, and seems to be running fine. When a certain event is fired, the event handler is supposed to read some information from a MySQL database and process the result set and write out an xml file to the file system. All seems to be working fine until the time comes to do the xml work. Below is the stack trace

Exception in thread "main" java.lang.AbstractMethodError: gnu.xml.dom.DomDocument.getXmlStandalone()Z
*     at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo(DOM2TO.java:373)*
*     at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:127)*
*     at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:94)*
*     at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:661)*
*     at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:707)*
*     at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)*
*     at testing.CreateDomXml.createDomXml(CreateDomXml.java:94)*
*     at testing.What.main(What.java:6)*

The initial through that I had was it could be related to the fact that I was using a Swing based class to create the xml document, but it seems that it is not the case as is shown from the code below:

This class is what I am using to create the xml document from another class as a simple sanity check !
package testing;

public class What {

     public static void main(String [] args){
          XMLCreator.testCreateXML()
     }
}

this is the class that creates the XML document
package testing;
import java.io.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;

public class XMLCreator {
public static void main (String args[]) {
     testCreateXML();
}

public static void testCreateXML() {
try {
//to create document to put DOM tree.
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();

//to create root element email
Element root = doc.createElement("email");
doc.appendChild(root);

//to create comment
Comment comment = doc.createComment("Sample XML format of Email ");
root.appendChild(comment);

Element subject = doc.createElement("subject");
root.appendChild(subject);

Text subText = doc.createTextNode("Message from TechLabs");
subject.appendChild(subText);

//to create child element from and text node of that element
Element from = doc.createElement("from");
root.appendChild(from);
Text fromText = doc.createTextNode("j2eeforum@rediffmail.com");
from.appendChild(fromText);

Element fromdisplay = doc.createElement("fromdisplay");
root.appendChild(fromdisplay);
Text fromdisplayText = doc.createTextNode("TechLabs");
fromdisplay.appendChild(fromdisplayText);

Element receipients = doc.createElement("receipients");
root.appendChild(receipients);

Element receipient = doc.createElement("receipient");
receipients.appendChild(receipient);
receipient.setAttribute("role", "to"); // to create attribute with value

Element email_id = doc.createElement("email-id");
receipient.appendChild(email_id);
Text emailidText= doc.createTextNode("vkj@xyz.com");
email_id.appendChild(emailidText);

Element disp = doc.createElement("display");
receipient.appendChild(disp);
Text dispText= doc.createTextNode("VKJ");
disp.appendChild(dispText);

Element bodytext = doc.createElement("bodytext");
root.appendChild(bodytext);
Text bodytextText = doc.createTextNode("Hope this URL will help you to learn about how to create XML using DOM.");
bodytext.appendChild(bodytextText);

Element sign= doc.createElement("signature");
root.appendChild(sign);
Text signText = doc.createTextNode("Administrator");
sign.appendChild(signText);

//to create transformer
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");

//to include the xml declaration line <?xml version="1.0" encoding="utf-8" standalone="no"?>
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");

//for indent of XML
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

// to write into a file
//String fileName= "/Users/Higgins/Desktop/sample.xml";
//StreamResult result = new StreamResult(new File(fileName));

DOMSource source = new DOMSource(doc);

//to write as a string
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
transformer.transform(source, result);
//System.out.println("XML file saved " + fileName);

String xmlString = sw.toString();
System.out.println("Email XML \n\n " + xmlString);

} catch (Exception e) {
System.out.println(e);
}
}
}



When run alone, class XMLCreator does the job perfectly. Can anybody provide some insight on the issue? or if anyone has encountered the same problem, please advise. Keeping in mind that I have changed the JDK from 1.4 to 1.5 to 1.6 to 1.7 and the JRE as well but nothing

higgins:~ higgins$ java -version
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04-415-11M3635)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01-415, mixed mode)

Eclipse Java EE IDE for Web Developers.

Version: Indigo Service Release 1
Build id: 20110916-0149

(c) Copyright Eclipse contributors and others 2005, 2011. All rights reserved.
Visit http://www.eclipse.org/webtools

Developing on a mac

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points