• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with compiling

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have read through all the steps here
http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html

I am trying to compile the hello world program and I keep getting these errors as seen in my attachment. What am I doing wrong here?
helpplease.jpg
[Thumbnail for helpplease.jpg]
my problem
 
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to add classpath.

execute the following command.

java -cp . HelloWorldApp
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James,
Welcome to the Ranch.

java HelloWorldApp will run the application. To compile, you need to run javac HelloWorldApp.java
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read the section Common Problems (and Their Solutions) in that same tutorial - it explains the exact error message you get and what to do about it.
 
james thompson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:James,
Welcome to the Ranch.

java HelloWorldApp will run the application. To compile, you need to run javac HelloWorldApp.java



Yes i have already compiled it using the javac HelloWorldApp.java and it made the .class file this is the error i get when i try to run this file.

I dont understand the cp? Where am I pointing it to?

Edit ok after further reading thanks to your guys suggestions I got it... Now here
set CLASSPATH=
Now enter java HelloWorldApp again. If the program works now, you'll have to change your CLASSPATH variable. To set this variable, consult the section in the JDK 6 installation instructions. The CLASSPATH variable is set in the same manner.

So i need to set the CLASSPATH variable somewhere else to avoid this problem in the future?
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

james thompson wrote:
Yes i have already compiled it using the javac HelloWorldApp.java and it made the .class file this is the error i get when i try to run this file.



Well your post title said help with compiling and you also said I am trying to compile the hello world program and I keep getting these errors
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CLASSPATH is set a list of directories or jar files separated by ";" (in windows).

CLASSPATH is used by JAVA Virtual machine to find the classpaths.

When you run "java HelloWorldApp", here *java* program is the virtual machine and *HelloWorlApp* is your main class.
So it will try to search for HelloWorldApp in CLASSPATH path, if it is defined.

If CLASSPATH is not defined, current directory is by default assumed as the classpath.


 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Will suggest you, to go through the following link..

http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please use copy-and-paste to post the error messages, not screen capture. Click the top left icon on the command window, then edit, then mark, then highlight the text with the mouse, then enter to copy to clipboard. It is much easier to read.

When you compiled the file, with

javac HelloWorldApp.java

I presume you got no error messages? If the file compiles, nothing happens; you only get error messages if something goes wrong. Try the "dir" instruction to see where the .class file is.
If it is in your current directory, try the earlier suggestion of

java -cp . HelloWorldApp

Remember the java tool doesn't require extensions.

If that doesn't work, post the code you are compiling.

You should not normally set a system classpath, but some applications eg QuickTime, set a system classpath which can b*gg*r up your normal Java settings. If that is the case add .; to the beginning of the system classpath. You can have several .s in your classpath; I have tried it, and it doesn't seem to do any harm.
 
james thompson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you guys for all the help now I can finally start working through my head first java book
 
Campbell Ritchie
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it working?
 
reply
    Bookmark Topic Watch Topic
  • New Topic