|
-
June 14th, 2005, 05:59 AM
#1
Begineers Java Problem
Hi
I have started java language yesterday and i am unable to run my first program.
I am following the book the complete reference of java by mc-graw hill.
It told me to run the program from the dos mode by compiling it with javac as
D:\javac Example1.java
It did not work so i went into the directory of java and then into bin and executed javac from there.
As expected a class Example1.class was created. I executed
D:\Program Files>j2sdk_nb>j2sdk1.4.2>bin>javac D:\a\Example1.java
Files were stored in the folder a in the drive drive d:
it compiled fine.
Now i tried the java command and it gave an error which i am unable to understand.
D:\Program Files>j2sdk_nb>j2sdk1.4.2>bin>java D:\a\Example1
The error is:
Exception in thread "main" java.lang.NoClassDefFoundError: D:\a\Example1
Please help me
i am unable to get the problem.
What should i do
 \"The Smilie Wars\" ... just arrived after the great crusades
 .... computers come to the rescue .... ah technology at last has some use.
-
June 14th, 2005, 06:02 AM
#2
Heres the code of the program
class Example1
{ public static void main(String args[])
{ System.out.println("This ia a simple java program.");
}
}
 \"The Smilie Wars\" ... just arrived after the great crusades
 .... computers come to the rescue .... ah technology at last has some use.
-
June 16th, 2005, 08:56 PM
#3
Try cd'ing into the directory where the program is, then do this
Code:
path=D:\Program Files\j2sdk_nb\j2sdk1.4.2\bin
javac Example1.java
java Example1
or get an ide that will compile and run for you. http://www.jcreator.com has a simple free one. Good luck.
-
June 19th, 2005, 02:43 PM
#4
Hmm, I had the exact same problem at my college , when they imaged the machines, they forgot to tell windows the correct classpath to find java. This sounds like your problem so here's how to fix it.
*Right-click 'My Computer'
*Select the 'Advanced' tab
*Scroll down to the 'Environment Variables' button
*Now notice the system variables pane...
*Find the vaiable 'path' and hit edit
*Now on the textfield where it says 'variable value' go all the way to the and add the directory location of javac.
This is what mine looked like...
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem; C:\j2sdk1.4.0_02\bin
Hit 'ok' and that should work for you. What your doing here is telling the computer where to look basically to compile. It does exactly what is posted above, just a different way. Perhaps slightly more confusing
Note: for this solution I am assuming you are using Windows XP
The real question is not whether peace can be obtained, but whether or not mankind is mature enough for it...
-
June 19th, 2005, 09:16 PM
#5
Hi,
Yup I think THE RADICA got that Right .......But you are setting the path varible RADICA not the classpath...... Path tells where to look for the java compiler and as it's compiling fine i don't think path needs to be set........ Sounds to me like the Classpath is not right ......... happens to me all the time in the School Lab .......... In the Book you are reading try reading the Packages Chapter classpath generally explained there .......... In my school lab Students **** up the class path when they make their own packages ....... few Morons when adding their own Classpath are too lazy to add that %classpath% ...... they would simply say set classpath=c:\userdirocetry instead of Set Calsspath=%classpath%;c:\userdirocetry 
OK enough Ranting i guess ........ Coming to your Problem ....... Try Setting that Classpath manually at the Command Prompt.
Somethig like
Set classpath=%classpath%;.;
then if dosen't work try this
Set classpath=%classpath%;D:\Program File\j2sdk_nb\j2sdk1.4.2\lib;.;
Assuming the path of your Lib Folder is that .
You see at the end ;.; ...... that DOT means include Current Diroctary to the class path generally that's the problem.
[EDIT]
ooo Just out of Sheer curiocity is the Class File which has the main() method Same as the File name ? .... it also happens if you don't have them same.
Peace
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
|
|