本文介绍了如何捕获java.lang.NoClassDefFoundError?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个应用程序,它使用elf文件(*。a和* .o)并给出方法名称列表,但是如果有人将任何文件重命名为* .a或* .o,则将显示:

 事件调度期间发生异常:
java.lang.NoClassDefFoundError:org / eclipse / core / resources / IWorkspaceRunnable
at org.eclipse.cdt.utils.AR。< init>(AR.java:237)
在com.lge.windowELF.ElfBinaryArchive。< init>(ElfBinaryArchive.java:24)
at com.lge.windowELF.ELFParserLibraryFile.createBinaryArchive(ELFParserLibraryFile.java:230)
at com.lge.windowELF.ELFParserLibraryFile。< init>(ELFParserLibraryFile.java:46)
at com.lge.windowELF .ELFWrapper。< init>(ELFWrapper.java:36)
在com.lge.windowELF.ELF_UIIntegrated.actionPerformed(ELF_UIIntegrated.java:510)
在javax.swing.AbstractButton.fireActionPerformed(未知来源)
在javax.swing.AbstractButton $ Handler.actionPerformed(未知源)
在javax.swing.De errorButtonModel.fireActionPerformed(未知源)
在javax.swing.DefaultButtonModel.setPressed(未知源)
在javax.swing.plaf.basic.BasicButtonListener.mouseReleased(未知源)
在java。 awt.Component.processMouseEvent(Unknown Source)
javax.swing.JComponent.processMouseEvent(Unknown Source)


$ b $在这种情况下,我想给一些警告信息。这个例外没有被try / catch捕获。

解决方案

不鼓励 href =http://download.oracle.com/javase/6/docs/api/java/lang/Error.html =nofollow> 错误 / A>! JavaDoc指出:

我的建议是,你整理 NoClassDefFoundError 并担心代码抛出的异常。



我宁愿在代码中抛出一个 invalidELFFileException (educated guess)on ElfBinaryArchive 构造函数类(或包装类并执行 throws 当实例化时)类尝试打开ELF文件。这样,如果有一个无效的ELF文件,抛出一个体面的异常。



或者,确保 org.eclipse.core.resources.IWorkspaceRunnable 必须放在CLASSPATH中。


I made an application which take elf file(*.a and *.o) and give list of methods name, but if someone renames any file into *.a or *.o then it will show:

Exception occurred during event dispatching:
java.lang.NoClassDefFoundError: org/eclipse/core/resources/IWorkspaceRunnable
    at org.eclipse.cdt.utils.AR.<init>(AR.java:237)
    at com.lge.windowELF.ElfBinaryArchive.<init>(ElfBinaryArchive.java:24)
    at com.lge.windowELF.ELFParserLibraryFile.createBinaryArchive(ELFParserLibraryFile.java:230)
    at com.lge.windowELF.ELFParserLibraryFile.<init>(ELFParserLibraryFile.java:46)
    at com.lge.windowELF.ELFWrapper.<init>(ELFWrapper.java:36)
    at com.lge.windowELF.ELF_UIIntegrated.actionPerformed(ELF_UIIntegrated.java:510)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)

In this situation I want to give some warning message. This exception is not caught by try/catch.

解决方案

It's not encouraged to catch an Error! JavaDoc states:

My suggestion is that you sort out the NoClassDefFoundError and worry about exceptions thrown by your code instead.

I would rather, in code, throw an InvalidELFFileException (educated guess) on ElfBinaryArchive constructor class (or wrap the class and do a throws when instantiating) when the class tries to open the ELF file. That way, if there's an invalid ELF file, a decent exception is thrown.

Alternatively, make sure org.eclipse.core.resources.IWorkspaceRunnable must be put in CLASSPATH.

这篇关于如何捕获java.lang.NoClassDefFoundError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 07:50