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*
*     at*
*     at*
*     at*
*     at*
*     at*
*     at testing.CreateDomXml.createDomXml(*
*     at testing.What.main(*

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){

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

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

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");

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

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

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

//to create child element from and text node of that element
Element from = doc.createElement("from");
Text fromText = doc.createTextNode("");

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

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

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

Element email_id = doc.createElement("email-id");
Text emailidText= doc.createTextNode("");

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

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

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

//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("{}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) {

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.

Developing on a mac


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