[英]Java can't find class in same package when I run Main from command line
I moved a class from Main.java into their own.java files and now the IDE (IntelliJ) can't find them, even though they are in the same package. Here are the first lines of Main...我将 class 从 Main.java 移到他们自己的 .java 文件中,现在 IDE (IntelliJ) 找不到它们,即使它们在同一个 package 中。这是 Main 的第一行...
package readability;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
var filePath = args[0];
var textAnalyser = new TextAnalyser(filePath);
... and here's the error I get when I run it from the command line: ...这是我从命令行运行它时遇到的错误:
C:\Users\123md\IdeaProjects\Readability Score\Readability Score\task\src\readability>java Main.java in.txt
Main.java:8: error: cannot find symbol
var textAnalyser = new TextAnalyser(filePath);
^
symbol: class TextAnalyser
location: class Main
Interestingly, when I just say String filePath = "in.txt"
and run it in the console, it does find the class and runs fine, so why can't it find the class when I run it from the command line?有趣的是,当我只是说
String filePath = "in.txt"
并在控制台中运行它时,它确实找到了 class 并且运行正常,那么为什么当我从命令行运行它时它找不到 class? Thanks!谢谢!
You can only run single *.java
file with java
command.您只能使用
java
命令运行单个*.java
文件。 If your program uses mutiple files, you have to compile it first:如果你的程序使用多个文件,你必须先编译它:
javac readability/Main.java readability/TextAnalyser.java
and then run:然后运行:
java readability.Main in.txt
For more info see: https://openjdk.java.net/jeps/330有关详细信息,请参阅: https://openjdk.java.net/jeps/330
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.