• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiler error

 
Emile Indik
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • 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
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic