遇到如下异常:
java.lang.ExceptionInInitializerError
at com.ts.org.dom4j.io.XMLWriter.escapeElementEntities(XMLWriter.java:2183)
at com.ts.org.dom4j.io.XMLWriter.writeNodeText(XMLWriter.java:1610)
at com.ts.org.dom4j.io.XMLWriter.writeNode(XMLWriter.java:1643)
at com.ts.org.dom4j.io.XMLWriter.writeElementContent(XMLWriter.java:1285)
at com.ts.org.dom4j.io.XMLWriter.writeElementContent(XMLWriter.java:1210)
at com.ts.org.dom4j.io.XMLWriter.writeElement(XMLWriter.java:1152)
at com.ts.org.dom4j.io.HTMLWriter.writeElement(HTMLWriter.java:781)
at com.ts.org.dom4j.io.XMLWriter.writeNode(XMLWriter.java:1637)
at com.ts.org.dom4j.io.XMLWriter.writeElementContent(XMLWriter.java:1291)
at com.ts.org.dom4j.io.XMLWriter.writeNode(XMLWriter.java:1678)
at com.ts.org.dom4j.io.XMLWriter.writeElementContent(XMLWriter.java:1291)
at com.ts.org.dom4j.io.XMLWriter.writeElement(XMLWriter.java:1157)
at com.ts.org.dom4j.io.HTMLWriter.writeElement(HTMLWriter.java:789)
at com.ts.org.dom4j.io.XMLWriter.writeNode(XMLWriter.java:1637)
at com.ts.org.dom4j.io.XMLWriter.writeElementContent(XMLWriter.java:1291)
at com.ts.org.dom4j.io.XMLWriter.writeElement(XMLWriter.java:1157)
at com.ts.org.dom4j.io.HTMLWriter.writeElement(HTMLWriter.java:789)
at com.ts.org.dom4j.io.XMLWriter.writeNode(XMLWriter.java:1637)
at com.ts.org.dom4j.io.XMLWriter.writeNode(XMLWriter.java:1624)
at com.ts.org.dom4j.io.XMLWriter.write(XMLWriter.java:413)
at com.ts.common.paint.vc.fc.html.TextCopyToHtml.processMain(TextCopyToHtml.java:475)
查看JDK文档:基本判定是静态初始化出的问题。
Class ExceptionInInitializerError
java.lang.Object
java.lang.Throwable
java.lang.Error
java.lang.LinkageError
java.lang.ExceptionInInitializerError
All Implemented Interfaces:
Serializable
public class ExceptionInInitializerError
extends LinkageError
Signals that an unexpected exception has occurred in a static initializer.
An ExceptionInInitializerError is thrown to indicate that an exception occurred
during evaluation of a static initializer or the initializer for a static variable.
As of release 1.4, this exception has been retrofitted to conform to the general purpose
exception-chaining mechanism. The "saved throwable object" that may be provided at
construction time and accessed via the getException() method is now known as the cause, and
may be accessed via the Throwable.getCause() method, as well as the aforementioned "legacy method."
Since:
JDK1.1
所以查看出错的代码:
static {
load0("/res/HTMLlat1.properties");
load0("/res/HTMLspecial.properties");
load0("/res/HTMLsymbol.properties");
load0("/res/XMLbuiltin.properties");
String value;
Object key;
Enumeration enu = ENTITIES.keys();
while (enu.hasMoreElements()) {
key = enu.nextElement();
value = (String) ENTITIES.get(key);
if (value != null) {
CHAR2ENTITIES.put(value.charAt(0), ("&" + key.toString() + ';'));
}
}
......
}
/* Loads the entity values in the specified resource. */
private static void load0(String filename) {
try {
ENTITIES.load(HTMLEntities.class.getResourceAsStream(filename));
} catch (IOException e) {
}
} // load0(String)
发现load0()方法加载properties文件(HTMLEntities.class.getResourceAsStream(filename))报错了,原因是资源文件不存在。添加相应的文件后异常解决。