“NoClassDefFoundError:无法初始化类”错误 [英] "NoClassDefFoundError: Could not initialize class" error

查看:285
本文介绍了“NoClassDefFoundError:无法初始化类”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行我的项目时,我会收到许多错误的输出:

When I run my project, I get numerous outputs of this error:


Sep 9, 2009 8:22:23 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Jersey threw exception
java.lang.NoClassDefFoundError: Could not initialize class SpringFactory
        at com.point2.prospect.persistence.hibernate.HibernateTransactionInterceptor.doFilter(HibernateTrans
actionInterceptor.java:17)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.point2.prospect.restapi.ServerErrorInterceptor.doFilter(ServerErrorInterceptor.java:27)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:619)

我注意到这个问题有一个模式被问及整个网络,但没有真正的答案。这种错误的一般原因是什么?

I notice that this problem has a pattern of being asked all over the web, but with no real answers. What is a general cause for this kind of error?

推荐答案

NoClassDefFound错误是一个模糊的错误,常常隐藏更严重的问题。它不是与ClassNotFoundException相同(当该类不在那里时抛出)。

NoClassDefFound error is a nebulous error and is often hiding a more serious issue. It is not the same as ClassNotFoundException (which is thrown when the class is just plain not there).

NoClassDefFound 可能指示类不存在,就像javadocs指示一样,但是在类加载器加载类的字节并在其上调用defineClass之后,通常会抛出该类。还要仔细检查您的完整堆栈跟踪其他线索或可能的原因异常(尽管您的特定回溯显示无)。

NoClassDefFound may indicate the class is not there, as the javadocs indicate, but it is typically thrown when, after the classloader has loaded the bytes for the class and calls "defineClass" on them. Also carefully check your full stack trace for other clues or possible "cause" Exceptions (though your particular backtrace shows none).

当您获得NoClassDefFoundError时,首先看在你的类的静态位,即在类的定义期间发生的任何初始化。如果失败,它将抛出一个NoClassDefFoundError - 它应该抛出一个ExceptionInInitializerError并指出问题的细节,但根据我的经验,这些是罕见的。它只会在第一次尝试定义该类时执行ExceptionInInitializerError,之后它将抛出NoClassDefFound。因此,请查看早期的日志。

The first place to look when you get a NoClassDefFoundError is in the static bits of your class i.e. any initialization that takes place during the defining of the class. If this fails it will throw a NoClassDefFoundError - it's supposed to throw an ExceptionInInitializerError and indicate the details of the problem but in my experience, these are rare. It will only do the ExceptionInInitializerError the first time it tries to define the class, after that it will just throw NoClassDefFound. So look at earlier logs.

因此,我建议您查看HibernateTransactionInterceptor行中的代码,并查看需要的内容。似乎无法定义SpringFactory类。所以也许检查该类中的初始化代码,这可能有帮助。
如果可以调试它,请在上面的最后一行(17)停止它,并调试,以便您可以尝试找到导致异常的确切行。还要检查日志中的较高,如果你很幸运的话可能会有一个ExceptionInInitializerError。

I would thus suggest looking at the code in that HibernateTransactionInterceptor line and seeing what it is requiring. It seems that it is unable to define the class SpringFactory. So maybe check the initialization code in that class, that might help. If you can debug it, stop it at the last line above (17) and debug into so you can try find the exact line that is causing the exception. Also check higher up in the log, if you very lucky there might be an ExceptionInInitializerError.

这篇关于“NoClassDefFoundError:无法初始化类”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆