• 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

Help with enums

 
Greenhorn
Posts: 13
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm taking Java SCJP certification course and I'm reading Kathy's guide, I've just started, so right now I'm reading about declaring enums, the book lists the following code


I'm assuming that code to be in a same file since enums can be declared within and outside a class, so I saved it into a file named "Coffee.java", it compiles just fine from command line but when I try to execute "java Coffee" it throws "Error: Could not find or load main class Coffee"

Can anyone point me out what am I doing wrong? I have some experience with Java in general but to be hones I have never used enums before, so I'm learning new stuff here.

Thanks in advance.
 
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
Trying to execute that class was what you did wrong. An enum isn't intended to be a standalone Java class which you can run.
 
Carlos Marquez
Greenhorn
Posts: 13
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Paul, enum and class Coffee are in the same file called "Coffee.java". Once I compile Coffee.java I'm getting the following class files
Directory of c:\java

02/25/2014 12:19 PM <DIR> .
02/25/2014 12:19 PM <DIR> ..
02/25/2014 12:19 PM 1,057 Coffee.class
02/25/2014 12:18 PM 635 Coffee.java
02/25/2014 12:19 PM 980 CoffeeSize.class

Then I try to run java Coffee and I'm getting the Error message.

Regards,
 
Carlos Marquez
Greenhorn
Posts: 13
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've found the issue, it seems that some old configuration with Netbeans and tomcat put CLASSPATH env variable with different values from what I needed. I've removed the classpath variable and it's working properly.

Thanks again for the help!
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good reason to avoid IDEs until you are developing large applications.
 
Paul Clapham
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
Sorry, I didn't notice that you had the two classes in one source file. I never do that and so I didn't notice when you did it.
 
Legend has it that if you rub the right tiny ad, a genie comes out.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic