• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with enums  RSS feed

 
Carlos Marquez
Greenhorn
Posts: 13
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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!
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good reason to avoid IDEs until you are developing large applications.
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!