我编译并尝试从CMD行执行的任何Java代码都会导致错误:
错误:找不到或加载主类
我尝试设置环境变量:
PATH = C:\ Program Files \ Java \ jdk1.8.0_202 \ bin
JAVA_HOME = C:\ Program Files \ Java \ jdk1.8.0_202
and with and with out:
CLASSPATH = C:\ Program Files \ Java \ jdk1.8.0_202 \ jre \ lib或
CLASSPATH = C:\ Program Files \ Java \ jdk1.8.0_202 \ jre \ lib \ rt.jar或
CLASSPATH =(代码目录)
以下是无法运行的简单测试程序的示例:
/**
* Experiment with println() and print()
*/
public class HelloGoodbye
{
public static void main(String[] args)
{
System.out.println("My First Hello!");
System.out.println("Hello again!");
System.out.print("Hello finally!");
System.out.print("Goodbye!");
}
}
这将产生: 错误:找不到或加载主类
答案 0 :(得分:0)
首先,您必须编译代码:
javac HelloGoodbye
将创建一个类文件(HelloGoodbye.class)。然后,您必须运行以下命令来运行程序:
java HelloGoodbye