|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Class not defined
I am in the early stage of trying to learn to Java/JSP, so I know nothing about how it works. I installed a war file from a book I found on how create MySQL/JSP/Servlet websites. I have tomcat running and the webapp can create a dbpool, but when I try to run the application I receive an error message that says "Class not defined". This is the only information in the tomcat log as well. How can I find out which class is causing the error? Also, what causes a class not defined error?
Finally, what is a good place to start learning how to program servlets, beans, etc. ? Thanks in advance |
|
#2
|
|||
|
|||
|
very simple, actually
To get error messages for exceptions put a try catch / block as such with code in the catch that will print the error
public void doPost(HttpServletRequest req, HttpServletResponse res) { try { //put offending code here } catch (Exception e) { System.err.println(e.getMessage() + "\n"); e.printStackTrace(); } When an exception occurs in the offending try block you will then get a full stack trace printed to you error log. In that code the exceptions should print a line or two like such. exception in doPost 28: This will be the line number of your code that caused the exception. BTW the above code is a little to generic for most servlets (The Exception e that is)....you really should go with more targeted exception blocks such as: catch (SQLException sqle) { System.err.println(sqle.getMessage()); System.out.println ("SQL Exception in doPost in AdInput.java"); } catch (InstantiationException ie) { System.err.println(ie.getMessage() + "\n"); ie.printStackTrace(); System.out.println("Instantiation Exception in adInput.java"); } catch (ClassNotFoundException cnfe) { System.err.println(cnfe.getMessage() + "\n"); cnfe.printStackTrace(); System.out.println("Class Not Found Exception in AdInput.java"); } catch (IllegalAccessException iae) { System.err.println(iae.getMessage() + "\n"); iae.printStackTrace(); System.out.println("IllegalAccess Exception in AdInput.java"); } Doing your try catch blocks like this doesnt help the servlet that much (Unless you want to free specific resources for individual exceptions) But it sure makes debugging a heck of a lot easier! Remeber though that you can only catch exceptions that it is possible for your code to throw (IE: you cant catch an SQLException if your not doing any database connecting in your code) The compiler REALLY doesnt like that & will give you the famous XXX Exception is never thrown in the corresponding try block. BUT in your case the error will probably not print because of the ClassNotDefined message. This usually means the path to your classes folder isnt correct or you have them in the wrong folder or you forgot to compile them. Make sure all of this is correct. Then again the error may be coming from an instantiation of another class than your servlet, which will print the error code out correctly. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Class not defined |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|