• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Compiler error

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I'm working with Mac OS X 10.5.8. I followed the guide on this website to create my first java program, and saved a file called "MooseGreetings.java" with this text copied from the guide:

I then proceeded to open a terminal window and type "javac MooseGreetings.java"
It had one error, it could not read it. I neglected doing the PATH thing, if that's the problem I'd be gracious for a short guide on how to do that. If not, any other thoughts would help.
Thank you.
Emile
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch. And welcome to Java.

One of the great things about java is that its error messages tend to be very informative; once one understands what to look for, the error messages tend to tell you exactly what is wrong and where.

One of the great things about people that read this forum is that, among us, we've all made most of the mistakes people are likely to make, and recognize the error messages, etc.

So please, now and in general: don't paraphrase the error message(s). Tell us what it says. Because you're learning, what you think it's talking about may be wrong, and we can correct that most easily if we have the information from the compiler (and, as you progress through your learning, the runtime).

"It had one error, it could not read it" just has too many 'its' (itss?)

rc
 
Marshal
Posts: 76885
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome again

I thought Macs came with Java™ already installed. Are you sure it is a PATH problem?

As for setting the PATH, I googled and found this. It appears very similar to how one does it on Linux.
 
Emile Indik
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. The Terminal message said
"error: cannot read: MooseGreetings.java
1 error"
When I inputted something random, like "sdkfchsdn.java", the same message, with "MooseGreetings.java" replaced by "sdkfchsdn.java" came up.
I don't think I'm even on the right track here. It probably has something to do with skipping the PATH step.
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think it has to do with skipping the "PATH step". I am not familiar with the Mac, but it appears the compiler is attempting to read the file and cannot. That suggests that the compiler is, in fact, being invoked, and setting PATH is for ensuring that the command can invoke the compiler.

This would happen if your default directory is not the same one that contains your MooseGreetings.java file. Assuming the Mac terminal window uses Unix-like commands, execute "ls" and see if the source file is there. If not, find out where you put it, and do a "cd" (for change directory) to that directory.

Then try "javac" again.

rc
 
I will suppress my every urge. But not this shameless plug:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic