SunQuest
           Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old August 7th, 2001, 01:53 PM
lmhill lmhill is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 1 lmhill User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old August 14th, 2001, 08:22 AM
DC Dalton DC Dalton is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: NE Pa.
Posts: 96 DC Dalton User rank is Private First Class (20 - 50 Reputation Level)DC Dalton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 h 29 m 32 sec
Reputation Power: 8
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Class not defined


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway