wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes catching NoClassDefFoundError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "catching NoClassDefFoundError" Watch "catching NoClassDefFoundError" New topic
Author

catching NoClassDefFoundError

fang eve
Greenhorn

Joined: Jun 22, 2006
Posts: 26
Is there any way to try catch this error: java.lang.NoClassDefFoundError?? thanks.

OR

Is there any method to check the package path?
[ June 29, 2006: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

Nothing to do with JSP, so moved to the Java in General (beginner) forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You should not try to catch this serious error, but solve it when it happens.


[My Blog]
All roads lead to JavaRanch
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Well, usually you shouldn't. I can imagine some contexts where it's a perfectly reasonable thing to do, e.g. if you're using a ClassLoader as part of a larger framework, and the failure of something within the ClassLoader isn't necessarily grounds to bring down the entire framework. However, this is the sort of thing you should only do if you're pretty sure you know what you're doing. This is tre of many Errors - yes you can catch them, and sometimes it's actually a good idea. But if you're not sure why the error might occur in the first place, and can't tell whether or not this should seriously affect the application, you shouldn't do it.

But to answer the original question as asked:

[fang eve ]: Is there any way to try catch this error: java.lang.NoClassDefFoundError??

Yes, if you are sure you want to do this, you catch it exactly the same way you would catch any Exception or other Throwable: with a catch block giving the name of the Throwable class you're trying to catch, or a superclass


"I'm not back." - Bill Harding, Twister
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

Don't try to catch NoClassDefFoundError. Any exception that ends with "...Error" should not be caught - it means something really unexpected happened in the JVM. It's not something a user program should try to handle.

If you want to load classes dynamically, use reflection (see the Javadoc documentation of the package java.lang.reflect and of class java.lang.Class).

If you try to create an instance of a class via reflection (using Class.forName(...)) and the class can't be found, you will not get a NoClassDefFoundError, but a ClassNotFoundException instead.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
To the extent this has been moved to the Beginner forum, I'll just say I disagree in general - but it's good enough advice for beginners. As long as they don't become trapped believing that's the case for the rest of their careers...
fang eve
Greenhorn

Joined: Jun 22, 2006
Posts: 26
i have the following import statement
<%@ page import= "com.a.core.io.Ano"%>
<%@ page import= "com.a.core.kernel.Ci"%>
<%@ page import= "com.a.serviceProviders.Spaa"%>
<%@ page import= "com.a.core.nlp.text.action.Xa"%>
<%@ page import= "com.a.apps.smart.Ssf"%>
<%@ page import= "com.a.sdk.An"%>
<%@ page import= "com.mysql.jdbc.Driver"%>


<jsp:useBean id="an" class="com.a.sdk.An" scope="application"/>
<jsp:useBean id="ano" class="com.a.core.io.Ano" scope="session"/>

i will get the Error.

However if i took away the line:
<jsp:useBean id="an" class="com.a.sdk.AgentNetwork" scope="application"/>
there wont be error.

Does this mean that the problem is cause by the bean? If yes, what is the problem?

thanks
[ June 30, 2006: Message edited by: fang eve ]
fang eve
Greenhorn

Joined: Jun 22, 2006
Posts: 26
Originally posted by Jesper Young:
Don't try to catch NoClassDefFoundError. Any exception that ends with "...Error" should not be caught - it means something really unexpected happened in the JVM. It's not something a user program should try to handle.




how to check the JVM? I placing my files on server. I can't check the JVM.
I can't check all the exception error (i using system.out.print) as i cant view the tomcat console. Is just purely from the web, i have no idea where went wrong. I check the log file, but the error is display as what the page shows. Any way to get what the tomcat console print out?
[ June 30, 2006: Message edited by: fang eve ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Send us the exception you've got (the full trace)
fang eve
Greenhorn

Joined: Jun 22, 2006
Posts: 26
HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:498)
at org.apache.jsp.ndpreceiver_edit_jsp._jspService(Unknown Source)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:51)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:129)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:125)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:300)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:374)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:743)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:866)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:595)

root cause

java.lang.NoClassDefFoundError
at sun.reflect.GeneratedConstructorAccessor5.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at java.lang.Class.newInstance0(Class.java:350)
at java.lang.Class.newInstance(Class.java:303)
at java.beans.Beans.instantiate(Beans.java:204)
at java.beans.Beans.instantiate(Beans.java:48)
at org.apache.jsp.ndpreceiver_edit_jsp._jspService(Unknown Source)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:51)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:129)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:125)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:300)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:374)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:743)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:866)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:595)

Apache Tomcat/4.1.31
[ June 30, 2006: Message edited by: fang eve ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[fang]: However if i took away the line:
<jsp:useBean id="an" class="com.a.sdk.AgentNetwork" scope="application"/>
there wont be error.


Ignoring the stack trace, it sounds like there's a missing (or out-of-date) jar file or war file somewhere. Specifically, whatever jar/war was supposed to define the class com.a.sdk.AgentNetwork - that's where the problem probably is.
fang eve
Greenhorn

Joined: Jun 22, 2006
Posts: 26
Ok, how do i check whether the jar file is out of date? i have check the jar file, they are in the correct path, i run the application using localhost, it can find the jar file.

Is only at the server, i gt this error. That make me wonder what is really wrong.
[ June 30, 2006: Message edited by: fang eve ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: catching NoClassDefFoundError
 
Similar Threads
[eclipse] any good .html plugin that you recommend?
unable to add App Project into testServer
Page implicit Object?
Suggestions for team cheer
Unadulterated petrol pumps in bangalore