java.lang.NullPointerException ..与xml文件结构有关吗?

时间:2011-02-28 15:11:14

标签: java

我遇到了以下运行时错误。我正在运行读取xml文件作为输入的代码,这是代码:http://pastie.org/1617011。 XML:http://pastie.org/1617014

Feb 28, 2011 4:07:29 PM org.apache.commons.digester.Digester peek
WARNING: Empty stack (returning null)
Feb 28, 2011 4:07:29 PM org.apache.commons.digester.Digester endElement
SEVERE: End event threw exception
java.lang.NullPointerException
    at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:209)
    at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:220)
    at org.apache.commons.digester.Rule.end(Rule.java:257)
    at org.apache.commons.digester.Digester.endElement(Digester.java:1345)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2938)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    at org.apache.commons.digester.Digester.parse(Digester.java:1871)
    at QueryPerformer.main(QueryPerformer.java:127)
Exception in thread "main" java.lang.NullPointerException
    at org.apache.commons.digester.Digester.createSAXException(Digester.java:3363)
    at org.apache.commons.digester.Digester.createSAXException(Digester.java:3389)
    at org.apache.commons.digester.Digester.endElement(Digester.java:1348)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2938)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    at org.apache.commons.digester.Digester.parse(Digester.java:1871)
    at QueryPerformer.main(QueryPerformer.java:127)
Caused by: java.lang.NullPointerException
    at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:209)
    at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:220)
    at org.apache.commons.digester.Rule.end(Rule.java:257)
    at org.apache.commons.digester.Digester.endElement(Digester.java:1345)
    ... 12 more

1 个答案:

答案 0 :(得分:1)

当解析器配置设置为创建QueryDoc时,您确定在将返回的对象强制转换为QueryPerformer时是否正确?另外,传递给addSetNext的方法似乎是指QueryPerformer中的一个方法,而不是QueryDoc,这也是stacktrace似乎指向的方法。