• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package (ing)

 
scott matzka
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to set up a package that includes some useful things for any card game, such as a Card class, Deck class, etc. Check out the beginning of each class below. Both classes are saved in directory C:/J24work/cardGame. I am receiving compile time errors described below. There are a bunch of other errors as I'm referencing any Card object. I didn't have any problems when I had these classes in the same directory without any package listed. What could be the problem. thanks.

Deck.java:7: cannot find symbol
symbol: class Card
location: class cardGame.Deck
private Card[] deck;



I have compiled like this on DOS
C:J24work/cardGame>javac Card.java
C:J24work/cardGame>javac Deck.java (errors on this one)

-could there be something with the Classpath?
 
Tony Docherty
Bartender
Posts: 2971
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-could there be something with the Classpath?
Yes. You need to add the path to the package root to the classpath ie C:\J24work
 
scott matzka
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just did that and got the compile to work. Thanks though. Also, I had to make sure I was in the J24work directory from the cmd line, and compile like this:

C:\J24work> javac cardGame/card.Java
C:\J24work> javac cardGame/deck.Java

now though I have a BlackJack.java file and BlackJackEvent.java file that don't seem to recognize each other anymore. They are both in the same directory, which is C:\J24work\blackjack and should inherently recognize each other due to default package access. I definitely have the .; in my Classpath set so ??.



Scott
 
scott matzka
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing. If I compile like this:

C:\J24work\blackjack>javac BlackJack.java or
C:\J24work\blackjack>javac BlackJackEvent.java

the only errors are that references to each other aren't recognized, but if I compile like this:

C:\J24work>javac blackjack/BlackJack.java or
C:\J24work>javac blackjack/BlackJackEvent.java

I get compile errors stating that package cardGame does not exist. These must all be related to classpath.

 
Campbell Ritchie
Sheriff
Pie
Posts: 49812
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am too tired to give lots of details, I am afraid, but please search through this forum. There is about 1 question a month about compiling with package names, and if you find those questions you will get lots of useful information. Also look at these two sections of the Java Tutorials.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic