My directory structure looks like this:
folder
└───subfolder
└───subsubfolder
I hava a Main.java in folder
and Main.java
uses class inside subsubfolder
.
Here is how I did:
import subfolder.*;
import subfolder.subsubfolder.*;
However, I got the message following when I execute javac Main.java
$ javac -g Main.java
Main.java:23: error: cannot access Node
Node root = new Node();
^
bad class file: ./subfolder/subsubfolder/Node.class
class file contains wrong class: subsubfolder.Node
Please remove or make sure it appears in the correct subdirectory of the classpath.
1 error
Is my way of importing class file wrong?
It says
package subfolder
The package declaration of Node
should say
package subfolder.subsubfolder;
Providing an example for clarity:
folder/
Your source root (typically called 'src')
folder/Main.java
class Main { ... } (no package declaration)
folder/subfolder
folder/subfolder/subsubfolder/Node.java
package subfolder.subsubfolder;
public class Node { ... }
If your Main
indeed lives in a package (i.e. if your situation is something like src/folder/Main.java
) then you should not do
cd src/folder
javac Main.java
you should do
cd src
javac folder/Main.java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With