• 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

Could not load main class error (on mac)

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, i'm brand new to java, like literally this is the first time I have ever attempted to java(am i using that verb right?), and i'm already failing. when running a basic "hello world" script(code located at bottom) from command line using the "java" command, I am met with the following error: "Could not find or load main class .users.rasellers0.desktop.java.HelloWorld".
Can anyone give me any insight into what this means and how to resolve it? it's important to note that i'm working from a macintosh, so if you can come from that point of view it would be greatly appreciated.

Code as follows:

 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you running from the command line? Are you in the same directory as the class file?
 
Ryan Sellers
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am running from command line, but I have no clue what directory i'm in, nor how to fix it.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe the Mac command line is Linux. To determine what directory you're in, type "pwd". To change directories, type "cd" and the directory you want to go to. If you don't know the command line language you might want to do this from an IDE.
 
Ryan Sellers
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See, i'm learning java from a book (Head First Java, which i'm told is apparently a good book), and they've advised that I use command line at first, so, i'm giving it an honest go. What directory should I be in? Do i need to be in the directory with the .class file? or the java directory?
 
Ryan Sellers
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, I totally just figured it out. Thanks for the help! Also, I feel really, really dumb now. So should I use the pwd/cd commands every time i need to compile something in command line?
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you're right. Command line first. Okay, how do you type the program in? From the GUI (Mac's graphical frontend) or the command line? You basically want to be in the same directory that you typed the code into. I know Linux but not the Mac environment. I've been told the Mac command line is Linux, so unless someone else tells us differently, let's go with that.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you should write the program and run it in the same directory for now.
 
Sheriff
Posts: 67747
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

Knute Snortum wrote:I believe the Mac command line is Linux.


No, Linux is Linux.

The default Mac OS X command shell is bash.

(But yes, it's just like the Linux bash shell, just not Linux.)
 
Bear Bibeault
Sheriff
Posts: 67747
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

Ryan Sellers wrote:So should I use the pwd/cd commands every time i need to compile something in command line?


No. Once you are in the correct directory, you don;t need to keep setting it again and again. So just once to make sure you are in the correct directory.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Knute Snortum wrote:I believe the Mac command line is Linux.


No, Linux is Linux.

The default Mac command shell is bash.

(But yes, it's just like the Linux bash shell, just not Linux.)



OT: it's not using the Linux kernel? If it is, I'd say it's Linux with a Mac GUI.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, a Mac does not usually use Linux. It does use some Unix‑like conventions, however.
A suggestion for your first program:
  • 1: Open shell
  • 2: mkdir java (or other suitable name)
  • 3: cd java
  • Next time you use stages 1 and 3 only, until your java folder is so full you have to create subfolders.
     
    Ranch Hand
    Posts: 411
    5
    IntelliJ IDE Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Since I'm teaching myself systems programming I've acquired a lot of knowledge about programming... and now I highly recommend beginning programmers to use the shell instead of an IDE, as its the primary interface between the user and the system...

    To add more information to what have already been given... when you save your source code file pay attention to where it is being placed on the file system (the directory where it is saved)... After noting this, when you open up your terminal window to make sure that the file is in your working directory you can run the ls command to list the files... if the file is displayed in the listing then you should have no problem compiling and running the application...
     
    Rico Felix
    Ranch Hand
    Posts: 411
    5
    IntelliJ IDE Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Linux and Mac are two distinct Operating Systems... Linux is not Mac and Mac is not Linux... What they both have in common is that they are built around the POSIX standard (Portable Operating System Interface for Unix) and the SUS (Single Unix Specification) therefore they will both have similarities, yet they are not the same thing...
     
    Put a gun against his head, pulled my trigger, now he's dead, that tiny ad sure bled
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic