|
 |
|
 |
 |
|
10-10-2005, 04:57 AM
|
#1 (permalink)
|
|
Registered User
Join Date: Oct 2005
Posts: 19
|
Running a java program
I have managed to succesfully compile the following java program and it has created the class file correctly.
However when I try to run the program DOS comes up with this error.
Exception in thread "main" java.lang.NoClassDefFoundError: then the file name
this is the code of the main file
Code:
public class Hello
{
public static void main (String[] args)
{
System.out.println("Hello World");
}
}
__________________
Last edited by redhead : 10-10-2005 at 06:57 AM.
Reason: Use of [code] tags added
|
|
|
10-10-2005, 07:00 AM
|
#2 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
|
Have you checked the documentation, specificaly the part about case sensitivity
Quote:
Be Careful When You Type
Type all code, commands, and file names exactly as shown. The Java compiler and interpreter are case-sensitive, so you must capitalize consistently.
Hello not equal hello
|
Suns forum reveals there might be an error in your $CLASSPATH setting, since some have had the exact same probelm.
|
|
|
10-10-2005, 07:28 AM
|
#3 (permalink)
|
|
Registered User
Join Date: Oct 2005
Posts: 19
|
sorry being new to all this, could u explain how i can change the classpath name
__________________
|
|
|
10-10-2005, 09:53 AM
|
#4 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,114
|
If you're using Windows, it depends on the version of Windows you're using. In XP, you can right-click on My Computer and select Properties. Click on the Advanced tab and at the bottom hit the button labeled "Environmental Variables". "CLASSPATH" should be listed under "System variables". Be sure to include "." in your classpath, as that can often be the source of "NoClassDefFound" errors.
In Windows, the CLASSPATH is broken up with semi-colons for each directory you wish to include.
|
|
|
10-10-2005, 10:18 AM
|
#5 (permalink)
|
|
Registered User
Join Date: Oct 2005
Posts: 19
|
A few path names was thrown around in that forum. so wot do i need to put in it and where will i need to save my java files.
__________________
|
|
|
10-10-2005, 03:20 PM
|
#7 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,114
|
Quote:
|
Originally Posted by Java2
A few path names was thrown around in that forum. so wot do i need to put in it and where will i need to save my java files.
|
You need "." so as to be able to run it from *anywhere*.
|
|
|
10-11-2005, 12:39 AM
|
#8 (permalink)
|
|
Registered User
Join Date: Oct 2005
Posts: 19
|
Ok, i have added a "." into the class path (i think anyway, unless i have got this entirely wrong) there is a link to my below. any mistakes please point it out.
http://i14.photobucket.com/albums/a3...7/untitled.jpg
then just copy the image and paste it into a new application, it should appear more clear.
__________________
|
|
|
10-11-2005, 12:51 AM
|
#9 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
|
Thats the $TEMP variable you're editing there.. It has nothing todo with $CLASSPATH.
|
|
|
10-11-2005, 12:52 AM
|
#10 (permalink)
|
|
Registered User
Join Date: Oct 2005
Posts: 19
|
ok, so how do i chage the classpath to "."
__________________
|
|
|
10-11-2005, 02:39 AM
|
#11 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
|
Follow the directions given by Belisarius, if theres no system variable named CLASSPATH, then create a new one and fill in the "." aswell as your location of your java installation ie: c:\program files\java\jdk1.5.0\bin\;.;%CLASSPATH%;
|
|
|
10-11-2005, 01:59 PM
|
#13 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,114
|
For the record, "c:\program files\java\jdk1.5.0\bin\" isn't useful in the CLASSPATH - it doesn't contain any Java classes.
Here's what I need to help you - I need screenshots of the following:
- Your source code (I want an actual screen shot, not a cut and paste).
- A directory listing of the code you're trying to run. (Type 'dir' in the cmd window. If the listing is too long for the window, create a new directory and move your code there).
- A compile and an attempt to run the program. Include an 'echo %CLASSPATH%' as well.
|
|
|
10-12-2005, 01:21 AM
|
#14 (permalink)
|
|
Registered User
Join Date: Oct 2005
Posts: 19
|
__________________
|
|
|
10-12-2005, 01:45 AM
|
#15 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,114
|
Don't use the full path when running the Java program, just run "java Hello".
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 12:35 AM.
|
Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle
|
 |
|