gpt4 book ai didi

Java,java.lang.reflect.InvocationTargetException 与 Digester 解析器

转载 作者:行者123 更新时间:2023-11-30 05:57:51 24 4
gpt4 key购买 nike

我有一个 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

最佳答案

在我看来很清楚:

Caused by: java.lang.NullPointerException
at CollectionIndexer.addDocument(CollectionIndexer.java:41)

你的问题就在那里。您需要在代码中采取更多防御措施以防止出现空引用。

附言将您的代码放入默认包中是非常糟糕的做法。您应该始终将类放入显式包中。

关于Java,java.lang.reflect.InvocationTargetException 与 Digester 解析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5110991/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com