[英]Java Error: Could not find or load main class
package src.sheet1.question1;
class OneFourTwoOne {
public static void main(String[] args) {
assert args.length == 1;
int x = Integer.parseInt(args[0]);
System.out.print(x);
while(x != 1) {
x = next(x);
System.out.print(" " + x);
};
}
static int next(int x) {
return ((x % 2) == 0) ? (x / 2) : (3*x + 1);
}
}
when I input :java OneFourTwoOne in the terminal, here occurs an error: Error: Could not find or load main class OneFourTwoOne How can I run it?当我在终端中输入 :java OneFourTwoOne 时,出现错误:错误:无法找到或加载主类 OneFourTwoOne 如何运行它?
Java cannot run your class because it is in a package. Java 无法运行您的类,因为它在一个包中。 Java expects the package name to be matched by the path to your file. Java 期望包名与文件路径匹配。
Create a directory structure that looks like this:创建一个如下所示的目录结构:
src
+-sheet1
+-question1
+-OneFourTwoOne.java
and compile your class into OneFourTwoOne.class
.并将您的类编译为OneFourTwoOne.class
。 Now switch the parent directory of src
, and execute the command现在切换src
的父目录,执行命令
java src.sheet1.question1.OneFourTwoOne
Java cannot run your class because it is in a package. Java 无法运行您的类,因为它在一个包中。 Java expects the package name to be matched by the path to your file. Java 期望包名与文件路径匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.