|
-
Jan 5th, 2003, 04:38 PM
#1
Thread Starter
Hyperactive Member
Exception in thread "main" java.lang.NoClassDefFoundError:
hello all,
i am starting a introductory java course next week and thought it would be nice to at least try to write-compile-run a simple java program.
here is my code
Code:
class fun {
public static void main(String[] arguments) {
// My first Java program goes here
String greeting = "Hello World";
System.out.println(greeting);
}
}
for some reason it's not letting me run it
after i installed the kit
in dos i write
java -version
and it gave me
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
so i know that it can find the jdk1.3 folder
so i went to the bin folder and compiled the above program
javac c:\javafile\fun.java
it worked since i had no message and a file was created on the same level called fun.class
so then i tried to run it
java c:\javafile\fun
and this is the message i got
C:\jdk1.3\bin>java c:\javafile\fun
Exception in thread "main" java.lang.NoClassDefFoundError: c:\javafile\fun
i then looked in the appendix and tried to add this line to my autoexc.bat file (i have win 98)
SET CLASSPATH=%CLASSPATH%;.;C:\jdk1.3\lib\tools.jar;c:\jdk1.3
the book said that this should fix my problem but i get still the same error 
can anyone tell me what i should check next?
why does it let me compile but not run?
help i'm stuck..
bsw
-
Jan 5th, 2003, 07:05 PM
#2
Thread Starter
Hyperactive Member
found my mistake,
i needed to run it from the same directory.
i was fooled because to compile it i needed to be in jkd1.3\bin
directory
bsw
-
Jan 6th, 2003, 04:59 PM
#3
For java you don't specify paths on the command line. You specify which class to run, and classes don't care about paths.
This is why you either need to be in the directory of the codebase or specify the directory of the codebase via the -classpath option.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 7th, 2003, 02:49 AM
#4
Dazed Member
bsw2112 take note that any changes to the autoexec.bat file only take effect once the computer is rebooted.
-
Jan 7th, 2003, 07:19 AM
#5
And you might want to add c:\jdk1.3\bin to your PATH in autoexec.bat. Then you can compile from everywhere.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|