【问题标题】:Can't run Hello World java program on Windows [duplicate]无法在 Windows 上运行 Hello World java 程序 [重复]
【发布时间】:2019-06-02 21:20:23
【问题描述】:
public class Main {
    public static void main(String[] args) {
        //Set your print into the console
        System.out.println("Hello World");
    }
}

我曾尝试通过命令提示符(cmd.exe)执行程序,但它不断将错误作为输出。

我希望得到你好世界,但我得到:

Error: could not find or load main class MyClass.java

【问题讨论】:

  • 请发布您的代码
  • 你在cmd中使用什么命令来编译和运行程序?
  • Error: could not find or load main class MyClass.java 这个名字在两个方面是错误的。 1) 你的班级叫Main,而不是MyClass。 2) JVM 启动一个.class 文件,而不是.java 源代码文件。
  • “你只能在 90 分钟内发布一次” 不,不要发布新问题,edit 当前问题!可以在任何时间编辑现有问题。

标签: java windows


【解决方案1】:

由于您几乎没有提供任何信息,因此很难判断错误在哪里。

这是打印“Hello World”的代码

public class Main {
    //Class name is irrelevent, but it must be the same as the filename

    //Define a main method, it HAS to be public, static and called 'main' and should     
    //receive a String array and return void (just copy the next row)
    public static void main(String[] args) {
        //Set your print into the console
        System.out.println("Hello World");
    }

}

现在通过在终端中输入来编译您的文件:

javac <the path to your .java file>

然后:

java <classname (here Main)>

【讨论】:

  • 非常感谢,但这与我在这里的代码相同。一直在尝试发布,但没有通过。
  • 你能再发一次吗?你也用包吗?
  • 请如何发布我的代码,因为它已检测为非代码格式。
  • 在每行之前放置四个空格 - 在您撰写帖子的文本区域顶部有一条说明。
  • 它写道“你只能在 90 分钟内发布一次”
猜你喜欢
  • 2014-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多