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

发布于 2024-10-19 03:25:49 字数 4511 浏览 5 评论 0原文

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

I've a Java app, working with Lucene and Apache commons Digester to parse a xml collection. After the first item is parsed, I get this error... What does it mean ?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瞎闹 2024-10-26 03:25:49

我看起来很清楚:

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

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

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

Looks pretty clear to me:

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

Your problem is right there. You need to more defensive in your code to protect against null references.

P.S. It's very bad practice to put your code into the default package. You should always put classes into an explicit package.

空城之時有危險 2024-10-26 03:25:49

CollectionIndexer 是您自己的类吗?它似乎在第 41 行抛出 NullPointerException。它由 SAX 事件解析器调用,因此被 InitationTargetException 包装。

顺便说一句:JVM 从最外层开始打印堆栈跟踪,最后显示最内层的异常。但由于最里面的异常是在开始时抛出的,因此它几乎总是最有趣的异常。因此,根据经验:始终查看异常堆栈跟踪中的最后一个 caused by 子句,因为它通常是最有趣的。

Is CollectionIndexer your own class? It seems like it throws NullPointerException on line 41. It is invoked by SAX event parser, hence being wrapped by InvocationTargetException.

BTW: JVM prints stack traces starting from the outermost one, displaying the innermost exception at the end. But since the innermost exception is thrown at the beginning, it is almost always the most interesting one. So as a rule of thumb: always look at the last caused by clause in exception stack trace, as it is typically the most interesting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文