• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sharing enum constants

 
Harry Henriques
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to compile from the directory that holds the start of your package structure (C:\).
 
Harry Henriques
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't work with the command line much but I think the following will work:
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64716
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please avoid red text. It's practically unreadable against the tan. Rather, use code tags to make code stand out.
 
Harry Henriques
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it, Bear. No red text.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic