java什么我不能运行Intellij Idea创建的类文件?
有一个简单的程序:
package com.test;
public class Main {
public static void main(String[] args) {
System.out.println("lol");
}
}
在Intellij Idea项目中,正确运行,但如果我按cmd运行类文件,比如java Main.class
,我会出错
Error: Could not find or load main class Main.class
如果我手动编译.java
,我会有一些错误
在.../jdk/bin
的$PATH路径中。在Intellij Idea中,指向SDK的路径.../jdk
有什么问题吗
谢谢
# 1 楼答案
你的班级不是
Main
,而是com.test.Main
。你应该使用:从编译输出的根目录(即,从与
com/
文件夹相同的位置)