PFranchise
PFranchise

Reputation: 6752

Compiler does not find other classes in the same directory

I wrote a Java program that has 3 classes. When, I use javac, I am getting errors whenever my main class attempts to interact with the other classes. Is there anything special that I need to do? I am just calling javac Main.java. Any help would be greatly appreciated.

Edit:

DFA myDFA = new DFA();
String test = args[0];
if(myDFA.accept(test))

and the error is:

Main.java:19: cannot find symbol
symbol: class DFA
location class dfa.Main

I have 3 of those errors

Upvotes: 2

Views: 7739

Answers (3)

irreputable
irreputable

Reputation: 45433

first, use an IDE. don't do cmd line.

if you use javac, you should give it all source files that should be compiled

javac Main.java DFA.java ... 

javac *.java

javac -sourcepath .  Main.java 

again, get an IDE, don't do cmd line.

Upvotes: -1

Raj
Raj

Reputation: 1770

You need to to compile the classes indivdually i.e. javac class1.java javac class2.java javac class2.java

etc.

and then execute as

java cp . MainClass.Main

Upvotes: 2

duffymo
duffymo

Reputation: 308763

Yes, you need to specify the classpath using the -classpath option on javac when you compile.

Try compiling like this:

javac -classpath . *.java

Note the 'dot' after -classpath. It tells the compiler to look in the current directory to find any .java files that it needs.

If you need other paths or JARs, you have to make sure that they appear in the -classpath as well.

Upvotes: 3

Related Questions