Page 1 of 2

java.lang.NoClassDefFoundError Please Help

Posted: Mon Dec 08, 2003 1:59 pm
by irishbloke
im using the java web devlopers pack 1.3
installed in ;
C:\jwsdp-1.3

when i run certain classes (when there name is no long see below for example i get the error)

java.lang.NoClassDefFoundError

==============================================
the problem is basically a class called Test will run while a class (identical codewise) called TestCustomerDao Wont run given the above error (it compiles fine)

sample class which wont run(code wise this is no problem)
======================================
// CustomerByNameCommand.java

/*
6 - dec - 03
note to myself
proble with this class
it doesnt work because the class name is too long?
the code is fine
*/

package web.proj3.command ;

import java.util.* ;
import java.sql.* ;
import java.io.* ;


/*
CustomerByNameCommand
Q4 (ii)
*/

import javax.servlet.* ;
import javax.servlet.http.* ;

import web.proj3.business.* ;
import web.proj3.dao.* ;
import web.proj3.exceptions.* ;



public class CustomerByNameCommand implements Command
{
private HttpServletRequest request ;
private HttpServletResponse response ;
private HttpSession session ;


public CustomerByNameCommand(HttpServletRequest aRequest,
HttpServletResponse aResponse,
HttpSession aSession)
{
request = aRequest ;
response = aResponse ;
session = aSession ;
}

public String execute()
{
String page = null ;
CustomerDao dao = new CustomerDao() ;
try
{
//has to be changed
String customerName = request.getParameter("customerName") ;
ArrayList customers = dao.getCustomersByName(customerName);

/*String customerName = request.getParameter("customerName") ;
ArrayList customers = dao.getCustomersByName(customerName) ;
if (customers.size() == 0)
{
request.setAttribute("errorMessage", "No customers with this name") ;
page = errorPage ;
}
else
{
request.setAttribute("customers", customers) ;
page = "/" + request.getParameter("command") + ".jsp" ; // i.e. /CustomersByName.jsp
}*/

if (customers.size() == 0)
{
request.setAttribute("errorMessage", NO_CUSTOMERS) ;
page = errorPage ;
}
else
{
request.setAttribute("customers", customers) ;
page = "/" + request.getParameter("command") + ".jsp" ; // i.e. /Customers.jsp
}

}
catch(DaoException e)
{
page = errorPage ;
request.setAttribute("errorMessage", e.getMessage() ) ;
}
return page ;
}

}

Posted: Mon Dec 08, 2003 2:31 pm
by MudGuard
Which system are you running?

Let me guess - the problem occurs when class name is longer than 8 characters (old DOS 8.3 restriction)...

Posted: Mon Dec 08, 2003 8:22 pm
by irishbloke
windows XP
although i think its ok now..as i added a dot to my classpath and it seems to have fixed the problem..

very annoying?

any ideas why it happened?

Posted: Tue Dec 09, 2003 12:24 am
by Bob Hansen
as i added a dot to my classpath
A dot actually stands for the current directory. So it would seem that your current directory must not have been in your path.

Two dots is the parent directory of the current (referenced) directory.

Example: cd..\..\.. will go up three levels in the directory structure.

(Guess I should use folders vs. directories today?) :?: :oops:

Posted: Mon Dec 15, 2003 5:51 pm
by Toni-Sama
I'm having this same problem. It keeps saying

"Exception in thread "main" java.lang.NoClassDefFoundError: Coins2
Press any key to continue . . ."

but I've added the "." in my classpath "c:\jdk1_4_2\bin\Toni\."

Is there anything else I'm doing wrong? The name (as you see above) is Coins2, so I know it's not the length of the name.

Posted: Mon Dec 15, 2003 5:55 pm
by s_reynisson
Add the "." as a seperate entry in your classpath, like:
"c:\jdk1_4_2\bin\Toni\;."
HTH

Posted: Mon Dec 15, 2003 8:10 pm
by Toni-Sama
Thank you, sir. That solved my only problem.

Posted: Sun Jan 25, 2004 1:05 am
by jac
same problem here from a newbie...

Where do I go to modify my classpath?

Posted: Sun Jan 25, 2004 1:24 am
by s_reynisson
What's your operating system?
For WinXP you can right click on My Computer, select "Properties",
select the "Advanced" tab, click "Environment Variables", under "System
variables" look for "classpath", create one if it does not exist. HTH

Posted: Sun Jan 25, 2004 1:48 am
by jac
THANK YOU!!! FINALLY! IT WORKS!

Enviromental Variables?

Posted: Mon Mar 29, 2004 12:50 am
by Tammy_P
Can someone please explain this to me, Please. I am getting the same error and have put in the suggested variable with no luck. I am working on a machine with WinXP professional it is home networked with another computer but I am the adminstrater. Would love to get this bug fixed soon Thanks in advanced for any help

Posted: Mon Mar 29, 2004 7:32 am
by agnul
Since java 1.1 everything works fine without an explicitly set CLASSPATH, if everything else is set up correctly. After the sdk installation you should (and I don't know why the installer script doesn't do that automagically) create an environment variable named JAVA_HOME pointing to the installation directory, and add $JAVA_HOME/bin to the command path. There's no need to create a CLASSPATH variable, and creating one may screw things up (for example forgetting to add current dir to it...)
Setting things up that way always worked flawlessly for me.

All the gory details about CLASSPATH and how the compiler/runtime go looking for classes are in the documentation, available both online and for download.

Hope that helps. :D

Thanks for responding

Posted: Tue Mar 30, 2004 5:06 am
by Tammy_P
My problem was I had a conflicting program that I had to delete. Does anyone have a quick fix for running textpad with Visual Studio 6.0?

Posted: Tue Apr 06, 2004 8:49 pm
by jgn1013
I'm having the same problem. I've already set up
CLASSPATH "c:\j2sdk1.4.1_06\bin\;." under the system enviroment on XP Pro. I finally got it compile by changing ther compile parameters but I can't figure out how to get this to run.

java sdk is installed under c:\ and my file are under d:\javaexamples\

Please help.

Posted: Tue Apr 06, 2004 9:22 pm
by s_reynisson
Your best start is the Java FAQ.
According to agnul above you don't need to do this, the classpath thing. What version of TP are you using? The current version is 4.7.2. Try opening a command window and entering "java -version" to see if it's accessible on your system. On my system under the tool "Run Java Application" I have Parameters=$BaseName and Initial Folder=$FileDir. If you are already using version 4.7.2 of TP try removing your Java tools and adding them again, without the classpath variable, and as a last resort you can uninstall/reinstall TP. HTH