Hello,

I have some Java code that must work for Java 1.4.2 and must use dom4j from
dynamically loaded code.  Unfortunately, I get an exception from dom4j when
I use it.

Here's a minimal program that exhibits the error followed by the error
message itself.  (This program works just fine with Java 1.6 BTW, I just
can't use that version.)

I'm hoping someone familiar with the dom4j code can suggest some classes to
explicitly load to avoid this problem.  Or, perhaps I need to use an older
version of dom4j (currently using 1.6.1)?  I know this code worked for some
version of Java 1.4 and some version of dom4j in the past.  I just don't
know what the magical combination was.

Thanks,

Bradford C. Smith

==== Main.java ====
package test;

import java.lang.reflect.Method;

public class Main {

/**
 * @param args
 */
 public static void main(String[] args) {
Class cl;
try {
 cl = Class.forName("test.Dynamic");
Method m = cl.getMethod("run", null);
 m.invoke(cl, null);
} catch (Exception e) {
e.printStackTrace();
 }
}

}

==== Dynamic.java ====
package test;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;

public class Dynamic {
public static void run() {
 Document doc = DocumentHelper.createDocument();
doc.addElement("startup");
 System.out.println("A dynamic \"Hello!\" to you.");
}
}

==== end Dynamic.java ====

The exception stack trace I get is this:

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:324)
at test.Main.main(Main.java:15)
Caused by: java.lang.ExceptionInInitializerError
at org.dom4j.QName.<init>(QName.java:69)
at org.dom4j.tree.QNameCache.createQName(QNameCache.java:236)
 at org.dom4j.tree.QNameCache.get(QNameCache.java:94)
at org.dom4j.DocumentFactory.createQName(DocumentFactory.java:203)
 at org.dom4j.DocumentFactory.createElement(DocumentFactory.java:148)
at org.dom4j.tree.AbstractDocument.addElement(AbstractDocument.java:172)
 at test.Dynamic.run(Dynamic.java:9)
... 5 more
Caused by: java.lang.NullPointerException
 at org.dom4j.tree.NamespaceCache.getURICache(NamespaceCache.java:154)
at org.dom4j.tree.NamespaceCache.get(NamespaceCache.java:84)
 at org.dom4j.Namespace.<clinit>(Namespace.java:28)
... 12 more
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to