• 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

Learning Java on Mac Air

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes...I know...I'm insane. I could easily fire up my Windows machine...but where's the fun in that.

I'm using the "Head First Java" book. Wrote "MyFirstApp" and it compiled with no problem.

However, when I try to run it, I'm getting a series of errors:



I think this has something to do with Classpath...but how do I set that on a Mac. Yes...I'm new to Mac too...Java and Mac all at once!

Thanks!
V
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

V Leandro wrote:Yes...I know...I'm insane.


You have plenty of company in the asylum. There are a lot of Java developers using Macs.

However, when I try to run it, I'm getting a series of errors:


Tell us exactly how you are trying to run the program and what setup you have done.

I assume you're doing this from the command line?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This looks like an ordinary classpath problem, just like the ones that everybody else has when they start learning Java.

As for "how to do it on Mac", when the tutorial shows you how to do it on Unix, that's how. You are following a tutorial or some other guide which shows you how to run Java programs at the command line, aren't you?
 
Ranch Hand
Posts: 71
Mac Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show us what you wrote in the file?
 
Alix Ollivier
Ranch Hand
Posts: 71
Mac Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you opened terminal, did you cd to the right directory? If not, use the command cd /file/path/here, or cd and drag in your file.
 
V Leandro
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Getting closer! From terminal I changed to the directory where MyFirstApp.class resides. I then ran the following:



The error has now changed....



Here's the code of my class:



Thanks for all the replies so far and your patience!

Virginia
 
V Leandro
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay...disregard that previous post!

The command I tried first this morning was javac which is the compiler! Doh!

I then reran the correct command of:



This worked! So the "trick" so far is to change into the directory where my class resides when running it in Java.

Thanks to everyone for your suggestions! For anyone else, I came across this site which jogged my memory.

http://docs.oracle.com/javase/tutorial/getStarted/problems/index.html" target="_blank" rel="nofollow">Common Problems

V
 
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
V Leandro, just be careful when you program to put your class in packages. If you plan to change your code to the following in future(which you will) and then run it


Then simply running won't help.

Java stores class files as fully qualified names and hence would be used to run the class.
reply
    Bookmark Topic Watch Topic
  • New Topic