Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
07-21-2009, 05:06 AM #1
- Join Date
- Apr 2009
- Thanked 0 Times in 0 Posts
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
07-21-2009, 05:38 AM #2
- Join Date
- Jun 2009
- Montreal, Canada
- Thanked 179 Times in 179 Posts
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.
Users who have thanked ckeyrouz for this post: