aspose file tools*
The moose likes Beginning Java and the fly likes sharing enum constants Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sharing enum constants" Watch "sharing enum constants" New topic
Author

sharing enum constants

Harry Henriques
Ranch Hand

Joined: Jun 17, 2009
Posts: 206
Hello,

I'm having a problem with packages and import statements when using an enum that is declared in one package, but that is used in another. In the test directory below, I am unable to figure-out why the MyTimesTest class cannot recognize the MyTimes enum. Do you have any suggestions?

Thanks
Harry









C:\home\enumeration>javac -cp . test\MyTimesTest.java
test\MyTimesTest.java:3: cannot find symbol
symbol : class MyTimes
location: package home.enumeration
import home.enumeration.MyTimes;
^
test\MyTimesTest.java:8: package MyTimes does not exist
System.out.println(MyTimes.MILLISECONDS.getQuantity() + " " +
^
test\MyTimesTest.java:9: cannot find symbol
symbol : variable MyTimes
location: class home.enumeration.test.MyTimesTest
MyTimes.MILLISECONDS);
^
3 errors

C:\home\enumeration>
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
You need to compile from the directory that holds the start of your package structure (C:\).
Harry Henriques
Ranch Hand

Joined: Jun 17, 2009
Posts: 206
Hi Tom,

Do you have any other suggestions. That suggestion doesn't seem to work.

Harry

C:\>javac -cp home\enumeration home\enumeration\MyTimes.java

C:\>javac -cp home\enumeration;home\enumeration\test home\enumeration\test\MyTimesTest.java
home\enumeration\test\MyTimesTest.java:3: cannot find symbol
symbol : class MyTimes
location: package home.enumeration
import home.enumeration.MyTimes;
^
home\enumeration\test\MyTimesTest.java:8: package MyTimes does not exist
System.out.println(MyTimes.MILLISECONDS.getQuantity() + " " +
^
home\enumeration\test\MyTimesTest.java:9: cannot find symbol
symbol : variable MyTimes
location: class home.enumeration.test.MyTimesTest
MyTimes.MILLISECONDS);
^
3 errors

C:\>
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
I don't work with the command line much but I think the following will work:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

Please avoid red text. It's practically unreadable against the tan. Rather, use code tags to make code stand out.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Harry Henriques
Ranch Hand

Joined: Jun 17, 2009
Posts: 206
Thanks Tom,

That works!

Harry

C:\>javac -cp . home\enumeration\test\MyTimesTest.java

C:\>java -cp . home/enumeration/test/MyTimesTest
1 MILLISECONDS

C:\>
Harry Henriques
Ranch Hand

Joined: Jun 17, 2009
Posts: 206
Got it, Bear. No red text.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I've removed the colouring from your posts. Please use colouring only to highlight important things. Using it for an entire section doesn't have any added value.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sharing enum constants