我是一个Java应用程序,与Lucene和Apache commons Digester一起解析xml集合。解析完第一个项目后,我收到此错误......这是什么意思?
Feb 24, 2011 5:53:16 PM org.apache.commons.digester.Digester endElement
SEVERE: End event threw exception
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:597)
at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:216)
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 CollectionIndexer.main(CollectionIndexer.java:103)
Caused by: java.lang.NullPointerException
at CollectionIndexer.addDocument(CollectionIndexer.java:41)
... 20 more
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 CollectionIndexer.main(CollectionIndexer.java:103)
Caused by: java.lang.NullPointerException
at CollectionIndexer.addDocument(CollectionIndexer.java:41)
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:597)
at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:216)
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
答案 0 :(得分:4)
对我来说很清楚:
Caused by: java.lang.NullPointerException
at CollectionIndexer.addDocument(CollectionIndexer.java:41)
你的问题就在那里。您需要在代码中更加防御以防止空引用。
P.S。将代码放入默认包中是非常糟糕的做法。您应该始终将类放入显式包中。
答案 1 :(得分:2)
CollectionIndexer
是你自己的班级吗?它似乎在第41行抛出NullPointerException
。它由SAX事件解析器调用,因此被InvocationTargetException
包裹。
BTW:JVM从最外层开始打印堆栈跟踪,最后显示最内层的异常。但是由于最里面的异常在开始时抛出,它几乎总是最有趣的。因此,作为经验法则:始终查看异常堆栈跟踪中的最后一个caused by
子句,因为它通常是最有趣的。