org.xml.sax.SAXParseException;systemId:……文件提前结束

对xml文档的访问中,出现下面的异常:

org.dom4j.DocumentException: Error on line 2 of document file:///d:/test/test.xml : 文件提前结束。
at org.dom4j.io.SAXReader.read(SAXReader.java:466)
at org.dom4j.io.SAXReader.read(SAXReader.java:250)
at org.xml.test01.main(test01.java:14)
Caused by: org.xml.sax.SAXParseException; systemId: file:///d:/test/test.xml; lineNumber: 2; columnNumber: 1; 文件提前结束。
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:449)
... 2 more


该异常出现的原因是xml文件中没有根节点,在xml文件中加入根节点,就可以解决该问题。


你可能感兴趣的:(Java学习中异常记录)