编译器在同一目录中找不到其他类 [英] Compiler does not find other classes in the same directory

查看:95
本文介绍了编译器在同一目录中找不到其他类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个具有3个类的Java程序.当我使用javac时,每当我的主类尝试与其他类进行交互时,都会出现错误.我需要做些特别的事情吗?我只是在调用javac Main.java.任何帮助将不胜感激.

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.

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

,错误是:

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

我有3个错误

推荐答案

是的,您需要在编译时使用javac上的-classpath选项指定classpath.

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

尝试这样编译:

javac -classpath . *.java

注意-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.

如果您需要其他路径或JAR,则必须确保它们也出现在-classpath中.

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

这篇关于编译器在同一目录中找不到其他类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆