java.lang.NoClassDefFoundError Please Help

Using the Java SDK with TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

irishbloke
Posts: 3
Joined: Thu Dec 04, 2003 6:56 pm

java.lang.NoClassDefFoundError Please Help

Post 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 ;
}

}
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post 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)...
irishbloke
Posts: 3
Joined: Thu Dec 04, 2003 6:56 pm

Post 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?
User avatar
Bob Hansen
Posts: 1517
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post 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:
Hope this was helpful.............good luck,
Bob
Toni-Sama
Posts: 2
Joined: Mon Dec 15, 2003 5:47 pm

Post 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.
User avatar
s_reynisson
Posts: 940
Joined: Tue May 06, 2003 1:59 pm

Post by s_reynisson »

Add the "." as a seperate entry in your classpath, like:
"c:\jdk1_4_2\bin\Toni\;."
HTH
Then I open up and see
the person fumbling here is me
a different way to be
Toni-Sama
Posts: 2
Joined: Mon Dec 15, 2003 5:47 pm

Post by Toni-Sama »

Thank you, sir. That solved my only problem.
jac
Posts: 3
Joined: Sat Jan 24, 2004 11:16 pm

Post by jac »

same problem here from a newbie...

Where do I go to modify my classpath?
User avatar
s_reynisson
Posts: 940
Joined: Tue May 06, 2003 1:59 pm

Post 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
Then I open up and see
the person fumbling here is me
a different way to be
jac
Posts: 3
Joined: Sat Jan 24, 2004 11:16 pm

Post by jac »

THANK YOU!!! FINALLY! IT WORKS!
Tammy_P
Posts: 2
Joined: Sun Mar 28, 2004 3:17 am
Location: denver

Enviromental Variables?

Post 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
agnul
Posts: 21
Joined: Tue Feb 10, 2004 9:42 am
Location: Italy

Post 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
Tammy_P
Posts: 2
Joined: Sun Mar 28, 2004 3:17 am
Location: denver

Thanks for responding

Post 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?
jgn1013
Posts: 2
Joined: Tue Apr 06, 2004 8:43 pm

Post 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.
User avatar
s_reynisson
Posts: 940
Joined: Tue May 06, 2003 1:59 pm

Post 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
Then I open up and see
the person fumbling here is me
a different way to be
Post Reply