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 s开发者_运维问答ymbol
symbol: class DFA
location class dfa.Main
I have 3 of those errors
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.
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
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.
精彩评论