trouble compiling

Thread Solved

Join Date: Jun 2007
Posts: 17
Reputation: snakai415 is an unknown quantity at this point 
Solved Threads: 0
snakai415 snakai415 is offline Offline
Newbie Poster

trouble compiling

 
0
  #1
Jun 29th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 4,845
Reputation: joshSCH is on a distinguished road 
Solved Threads: 10
joshSCH's Avatar
joshSCH joshSCH is offline Offline
Banned

Re: trouble compiling

 
0
  #2
Jun 29th, 2007
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:

  1. public static void main(String[] args)
  2. {
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 30
Reputation: Rayhan Muktader is an unknown quantity at this point 
Solved Threads: 3
Rayhan Muktader Rayhan Muktader is offline Offline
Light Poster

Re: trouble compiling

 
0
  #3
Jun 29th, 2007
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.
I don't reply to private messages.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 17
Reputation: snakai415 is an unknown quantity at this point 
Solved Threads: 0
snakai415 snakai415 is offline Offline
Newbie Poster

Re: trouble compiling

 
0
  #4
Jun 29th, 2007
Originally Posted by Rayhan Muktader View Post
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 17
Reputation: snakai415 is an unknown quantity at this point 
Solved Threads: 0
snakai415 snakai415 is offline Offline
Newbie Poster

Re: trouble compiling

 
0
  #5
Jun 29th, 2007
Originally Posted by Rayhan Muktader View Post
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 have no idea what you're talking about. :[
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,191
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 485
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: trouble compiling

 
0
  #6
Jun 29th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 17
Reputation: snakai415 is an unknown quantity at this point 
Solved Threads: 0
snakai415 snakai415 is offline Offline
Newbie Poster

Re: trouble compiling

 
0
  #7
Jun 29th, 2007
I didn't copy and paste, I just typed down the step-by-step guide that was written in the book.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 30
Reputation: Rayhan Muktader is an unknown quantity at this point 
Solved Threads: 3
Rayhan Muktader Rayhan Muktader is offline Offline
Light Poster

Re: trouble compiling

 
0
  #8
Jun 29th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,616
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 466
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: trouble compiling

 
0
  #9
Jun 29th, 2007
> 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.
Last edited by ~s.o.s~; Jun 29th, 2007 at 3:06 pm.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 17
Reputation: snakai415 is an unknown quantity at this point 
Solved Threads: 0
snakai415 snakai415 is offline Offline
Newbie Poster

Re: trouble compiling

 
0
  #10
Jun 30th, 2007
Originally Posted by Rayhan Muktader View Post
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?
-Copy and paste the java code?
-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)]


Originally Posted by ~s.o.s~ View Post
> 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.
-After I used notepad to create Example.java, I have the same problem.
-"(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)


Originally Posted by fastmike View Post
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC