Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-21-2009, 04:06 AM   PM User | #1
Stephandeye
New to the CF scene

 
Join Date: Apr 2009
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Stephandeye is an unknown quantity at this point
NoClassDefFoundError

I am trying to run two different programs created by classmates, both programs compile but when I try to run them I am getting the following error:

"Exception in thead "main" java.lang.NoClassDefFoundError: <wrong name>
Could not find the main class"

Both classmates insist that their programs run fine on thier computers. Also I have no porblems running my own assignment as well as assignments for other classmates.

I did a bit of research and found on java.sun that the error is telling me the definition of the class file exists at compile time but can no longer be found.

Is there anything that I am doing wrong? Another classmate told me to add -classpath . classname when running it from the command window but this also did not work.

Any advice woud be appreciated. Thanks
Stephandeye is offline   Reply With Quote
Old 07-21-2009, 04:38 AM   PM User | #2
ckeyrouz
Senior Coder

 
ckeyrouz's Avatar
 
Join Date: Jun 2009
Location: Montreal, Canada
Posts: 1,044
Thanks: 5
Thanked 179 Times in 179 Posts
ckeyrouz is on a distinguished road
The problem is there is an incompatibility between the location where you exist in the command prompt and the hierarchy of the java packages you have.

First of all you have to add the package to your classpath.

I will give examples on how you can do it:
Let's suppose that you have a folder named myclasses somewhere under C drive and in it you have the package com.mypackage and in it you have the class you need to execute , name it MyClass.

you can call it in 2 ways:
set your prompt at the folder c:\myclasses:
C:\myclasses> java com.mypackage.MyClass (make sure to call the class using its full path)

or you can be anywhere supposedly on c:\
c:\> java -classpath c:\myclasses com.mypackage.MyClass
here as well you need to call the java class using its full package.

Hope this was useful to you.
ckeyrouz is offline   Reply With Quote
Users who have thanked ckeyrouz for this post:
Stephandeye (07-23-2009)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:05 AM.


Advertisement
Log in to turn off these ads.