1

Sorry to ask a quite common question but I can't find a working answer. I just want to compile using javac several source files organized like this:

  • AdaptiveHuffmanCoding/
    • Encoder.java
    • Decoder.java
    • FullBinaryTree/
      • Node.java
      • Tree.java

For example, if I run

javac FullBinaryTree/Node.java

it works OK the class file is produced.

But if I run

javac FullBinaryTree/Tree.java

it will fail, reporting every Node appearance with an unknown symbol error.

As you can see the 2 files are in the same package so I'm not using any import and they are sharing the same 1st line namely

package AdaptiveHuffmanCoding.FullBinaryTree;

I guess I have to tell the compiler where to find this Node but I'm actually struggling with it. If someone could explain.

Thanks

1
  • yes, you have to configure classpath to tell compiler where to find other classes Commented Apr 2, 2018 at 16:17

1 Answer 1

1

As you can see the 2 files are in the same package...

To make classes of the same package accessible by the compiler, don't execute javac directly from this package but do it from the upper lever.

To compile the Tree class :

javac AdaptiveHuffmanCoding/FullBinaryTree/Tree.java

To compile all classes of this package :

javac AdaptiveHuffmanCoding/FullBinaryTree/*.java

Note that to be compliant with Java naming conventions : packages should not contain any uppercase characters.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks.Now I have another error but it smells better. Bad class file: ./AdaptiveHuffmanCoding/FullBinaryTree/Node.class class file contains wrong class: AdaptiveHuffman.FullBinaryTree.Node Please remove or make sure it appears in the correct subdirectory of the classpath.
You are welcome Ben :) It seems that AdaptiveHuffmanCoding/FullBinaryTree/Node.class should contain the AdaptiveHuffmanCoding.FullBinaryTree.Node class but it contains the AdaptiveHuffman.FullBinaryTree.Node class. AdaptiveHuffman differs from AdaptiveHuffmanCoding . Ensure that the packages and the directories be consistent.
OMG I must close the computer a bit and rest. Thanks again.
You are right as there is a time for each thing :) You are welcome again :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.