| | |
trouble compiling
Thread Solved |
•
•
Join Date: Jun 2007
Posts: 17
Reputation:
Solved Threads: 0
Hello, I am new at this java thing... like really, 1 day new.
I have this book called Java 2: A Beginner's Guide (Second Edition).
I got stuck on the second step which tells me to..
use javac to compile Example.java.. I read old posts that were posted here through google but.. it still failed.
Here is what I did:
i changed the cd to C:\java\bin..
javac Example.exe ENTER
java Example ENTER
then an error pops out:
Exception in thread "main" java.lang.NoClassDefFoundError: Example
How do I fix this? Can anyone help me?
Thanks.
I have this book called Java 2: A Beginner's Guide (Second Edition).
I got stuck on the second step which tells me to..
use javac to compile Example.java.. I read old posts that were posted here through google but.. it still failed.
Here is what I did:
i changed the cd to C:\java\bin..
javac Example.exe ENTER
java Example ENTER
then an error pops out:
Exception in thread "main" java.lang.NoClassDefFoundError: Example
How do I fix this? Can anyone help me?
Thanks.
Do you have a main method in your program? All java programs must have the following in order to compile and execute on their own:
Java Syntax (Toggle Plain Text)
public static void main(String[] args) {
•
•
Join Date: Jun 2007
Posts: 17
Reputation:
Solved Threads: 0
•
•
•
•
Javac Example.exe ENTER This command must have failed. Did you not get any error message? Java source code files have the extension .java not exe. Check your book's example closely.
oops sorry, that was a typo.. it was really Example.java
•
•
•
•
Originally Posted by joshSCH
Do you have a main method in your program? All java programs must have the following in order to compile and execute on their own
I am just following what the book was telling me to do.
The first step told me to make a wordpad document and name it:
Example.java
Second step:
Execute javac and compile Example.java to turn it into Example.class or something like that.
snakai415 it is nice for once that somebody tries to learn Java through command line. However, I hope this was just one of few examples which you had to copy and paste from somewhere else. So if the book come also with electronic version of source code for examples, try to avoid it and type it . You will make typos which will triger plenty of error message, but that way you will learn to handle them. With copy and paste you will never learn. So if you get in trouble just post here and we will be happy to help you...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Oct 2006
Posts: 30
Reputation:
Solved Threads: 3
Copy and paste the java code here. Then someone can easily point out the errors. Your error message states that it did not find a compiled file called Example.class. Did you see a file called Example.class appear in the same folder after running the javac command?
Last edited by Rayhan Muktader; Jun 29th, 2007 at 1:50 pm.
I don't reply to private messages.
> The first step told me to make a wordpad document and name it:
Wordpad is not a text editor, its a word processor. It inserts its own headers in the saved file. You need to use notepad. In short you need something which saves the files in plain text format and not add its own headers.
Type the code from the book in a notepad, save it at a place you want, go to that folder, run the javac command properly (I assume that you must have set the class path).
After having completed the following steps successfully, you must get a class file in the same folder (provided you have not kept a package declaration). Use the java command to run the program.
If you want names of few good text editors, just let us know.
Wordpad is not a text editor, its a word processor. It inserts its own headers in the saved file. You need to use notepad. In short you need something which saves the files in plain text format and not add its own headers.
Type the code from the book in a notepad, save it at a place you want, go to that folder, run the javac command properly (I assume that you must have set the class path).
After having completed the following steps successfully, you must get a class file in the same folder (provided you have not kept a package declaration). Use the java command to run the program.
If you want names of few good text editors, just let us know.
Last edited by ~s.o.s~; Jun 29th, 2007 at 3:06 pm.
I don't accept change; I don't deserve to live.
•
•
Join Date: Jun 2007
Posts: 17
Reputation:
Solved Threads: 0
•
•
•
•
Copy and paste the java code here. Then someone can easily point out the errors. Your error message states that it did not find a compiled file called Example.class. Did you see a file called Example.class appear in the same folder after running the javac command?
-I did not see a Example.class in my folder after I typed:
javac Example.java
[I did change the directory of Command Prompt to C:\java\bin (where my javac/java/Example.java is located)]
•
•
•
•
> The first step told me to make a wordpad document and name it:
Wordpad is not a text editor, its a word processor. It inserts its own headers in the saved file. You need to use notepad. In short you need something which saves the files in plain text format and not add its own headers.
Type the code from the book in a notepad, save it at a place you want, go to that folder, run the javac command properly (I assume that you must have set the class path).
After having completed the following steps successfully, you must get a class file in the same folder (provided you have not kept a package declaration). Use the java command to run the program.
If you want names of few good text editors, just let us know.
-"(I assume that you must have set the class path)." What does that part mean?
Sorry guys, I'm really bad at this.

I followed this guy's guide. (http://www.daniweb.com/forums/thread8505-2.html)
•
•
•
•
ok THIS WILL WORK FOR SURE.
delete everything and go to this download page and download the j2sdk1.4.2_12 version for windows.
http://java.sun.com/j2se/1.4.2/download.html
Then download this version.
J2SE v 1.4.2_12 SDK includes the JVM technologyhttp://java.sun.com/images/pixel.gifThe J2SE Software Development Kit (SDK) supports creating J2SE applications. More info...http://java.sun.com/images/pixel.gifDownload J2SE SDKhttp://java.sun.com/images/pixel.gifInstallation Instructions ReadMe ReleaseNotes
Sun License Third Party Licenses
i am assuming you know how to install anyways after installing you need to know where your j2sdk1.4.2_12 folder is. just for instance lets assume you have it in c drive. go to start and then run command prompt window. enter cmd. you should have a path something like this
c:\documents and settings\chris
well do this first
cd..
after that you will have c:\\documents and settings
well do the same thing one last time so then you are in your c:\
cd..
now you will have the screen something like this
C:\
i am assuming your j2sdk folder is in c drive so you will do this next
cd j2sdk1.4.2_12 (then press enter)
now you will see your command prompt like this
c:\j2sdk1.4.2_12
then just type one last command.
cd bin
now your command prompt looks like this
c:\j2sdk1.4.2_12\bin
Thats it BOYyYyyyYyy You got it. The next thing you need to do is type your code in a notepad and make sure MAKE SURE YOU SAVE IT IN THE BIN FOLDER WHICH IS IN J2SDK1.4.2_12 and save it as a .java file e.g(HelloWorldApp.java) in the bin folder.
Now go to your command prompt i hope it is still in bin directory
type this
javac HelloWorldApp.java
no errors HURRAY !!!!
then type java HelloWorldApp
Have fun BoYyYyyYy
Last edited by snakai415; Jun 30th, 2007 at 2:24 am.
![]() |
Similar Threads
- makefile c++ (C++)
- Word Frequency Counter Help (Java)
- Visual C++.NET programming problem (C++)
- float declaration problem (Java)
- what OS to use? (Getting Started and Choosing a Distro)
Other Threads in the Java Forum
- Previous Thread: Write and Read text files
- Next Thread: JCreator- command line prompt
| Thread Tools | Search this Thread |
2dgraphics 3d @param affinetransform android api apple applet application arc arguments array arrays automation binary binarytree bluetooth byte chat chatprogramusingobjects class client code color compare component count database derby design detection eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide if_statement image input integer interface j2me java java.xls javadesktopapplications javaprojects jni jpanel julia keytool keyword linux list loop macintosh map method methods mobile netbeans newbie object os pong problem producer program programming project projectideas read recursion replaysolutions rim scanner server set size sms sort sql string swing terminal threads transforms tree ui unicode web windows






(HelloWorldApp.java) in the bin folder.