File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes package (ing) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "package (ing)" Watch "package (ing)" New topic
Author

package (ing)

scott matzka
Greenhorn

Joined: Jan 31, 2006
Posts: 9
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

Joined: Aug 07, 2007
Posts: 2172
    
  47
-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

Joined: Jan 31, 2006
Posts: 9
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

Joined: Jan 31, 2006
Posts: 9
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

Joined: Oct 13, 2005
Posts: 37985
    
  22
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package (ing)
 
Similar Threads
Set Ant Classpath for Compile
syntax error using a method
compilation failed
compilation failed
errors generated when running Ant build file in Eclipse