Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Runtime Exception when using Dom4j to Create XML File in Eclipse

807607Jan 10 2007 — edited Jan 17 2007
Hi ppl!

I'm new to Dom4j and have been reading online.

I tried the following program. The program compiles fine but I get a runtime error in a message box "Fatal Exception Occured. Program will exit".

I use Eclipse 3.2 and dom4j-1.5.2

Any help on resolving the issue would be great.

The program is as follows.

package mypackage;

import java.io.FileWriter;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

public class XMLCreator
{
Document document;

public void createDocument()
{
document = DocumentHelper.createDocument();
Element root = document.addElement( "root" );

Element author1 = root.addElement( "author" )
.addAttribute( "name", "James" )
.addAttribute( "location", "UK" )
.addText( "James Strachan" );

Element author2 = root.addElement( "author" )
.addAttribute( "name", "Bob" )
.addAttribute( "location", "US" )
.addText( "Bob McWhirter" );
}

public void write()
{
try
{
//lets write to a file
XMLWriter writer = new XMLWriter(new FileWriter( "output.xml" ));
writer.write( document );
writer.close();

// Pretty print the document to System.out
OutputFormat format = OutputFormat.createPrettyPrint();
writer = new XMLWriter( System.out, format );
writer.write( document );

// Compact format to System.out
format = OutputFormat.createCompactFormat();
writer = new XMLWriter( System.out, format );
writer.write( document );
}
catch(Exception e)
{
e.printStackTrace();
}
}

public static void main(String args[])
{
XMLCreator xc = new XMLCreator();
xc.createDocument();
xc.write();
}

}


The error is as follows.


java.lang.NoSuchMethodError: com.trend.iwss.jscan.appscan.runtime.PolicyProps: method <init>()V not found
at com.trend.iwss.jscan.appscan.runtime.Session.<init>(Session.java:58)
at com.trend.iwss.jscan.appscan.runtime.Session.<clinit>(Session.java:33)
at org.dom4j.DocumentFactory.<clinit>(DocumentFactory.java)
at org.dom4j.DocumentHelper.createDocument(DocumentHelper.java:34)
at mypackage.XMLCreator.createDocument(XMLCreator.java:17)
at mypackage.XMLCreator.main(XMLCreator.java:60)

Exception in thread "main"
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 14 2007
Added on Jan 10 2007
13 comments
992 views