Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error message in terminal

 
Scott Walker
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im right at the beginning following a tutorial from a book.......when i type in javac MyFirstApp.java it comes up with a cannot be read error 1 message. I tried using textwrangler but the message still comes up. Am i supposed to save the file somewhere in particular because it is just on my desktop at the moment? I think it is a plain text document as well. I know someone had this problem before.....any suggestions? Thanks people.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Desktop isn't the best place for organizational purposes (I'd create a specific development folder), but that won't cause any other problems.

Be sure that the file is a plain text file. One way might be to type:

cat YourJavaFile.java

at the command line and make sure it looks correct.

Also, it would help when reporting problems to show us the exact error message that you are getting. Cut and paste from the Terminal window should work just fine.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you changing to the correct directory?

When you open Terminal, type cd (for "change directory") followed by a space and the path of the directory that contains your .java file, then hit return.

For example, I dump a lot of stuff under java/tests, so when Terminal opens, I type: cd java/tests
 
Scott Walker
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do i need to create a directory like java/tests to dump the stuff in? if so how do i do that? Thanks again for the advice guys.....i did warn you im right at the beginning haha and desperate to get started, take care
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Finder, navigate to where you want the new folder, then select "New Folder" from the File menu. Or instead of the File menu, you can use the "gear" action button at the top of Finder.

(Tip: At the top of Finder are also 3 view selection buttons: icons, list, and columns. To make sure the directory goes where you expect it to, avoid using the list view.)

As an alternative to using Finder, there's also a geek approach: The Unix command to make a directory in Terminal is mkdir followed by a space and the name of the directory (folder) you want to create.
 
Scott Walker
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok so at first it wouldnt recognise that id made a new directory in my documents folder....but then i tried the mkdir command in terminal and that seemed to work because my terminal prompt now has /java at the end.

but still when i type javac MyFirstApp.java i get this

error: cannot read: MyFirstApp.java
1 error

and when i tried typing cat MyFirstApp.java i get this

cat: MyFirstApp.java: No such file or directory


is there somewhere in particular i need to put my directory? This is so frutrating as i really dont know what im doing wrong and im so close to getting started! Thanks again for your help guys.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears that your problems aren't with java at all but in dealing with the unix command line.

The error from the cat command means that the file is not in that folder. You need to get a handle on how to use the command line.

No special folder is required, but you must place the file in the folder you will compile it from. (It gets a bit more complicated when you start using packages, but one step at a time.)

I'd recommend finding a book or other resource on using the unix command line before proceeding.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
 
Scott Walker
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys....i'll read it
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good move! Without a working knowledge of using the command line, you'll find yourself struggling with simple issues that will just get in the way of trying to actually program.

I know it probably seems frustrating and you want to just dive into the programming aspect -- after all, that's the fun part! -- but learning your way around the command line will serve you well on all levels.

And by the way, recommending the book was not a way to say "go away and RTFM"! We're all still here to answer your questions and help you along.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another good one is The Mac OS X Command Line: Unix Under the Hood by Kirk McElhearn.
 
Scott Walker
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no worries.....i really appreciate your help so far. You're right though.....i dont know anything about using the unix command line.....but i will, see you soon
 
stella marsh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see my answer to your question about how i solved this...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic