简体   繁体   English

Java:找不到或加载主类Main

[英]Java: could not find or load main class Main

I run my program from terminal, while it runs fine from IntelliJ. 我从终端运行程序,而从IntelliJ正常运行。 I get the error "could not find or load main class Main". 我收到错误消息“找不到主类Main”。 It's not the filenames that is incorrect and neither does the file have any specified package name. 并非文件名不正确,文件也没有任何指定的程序包名称。

here is my Main.java file. 这是我的Main.java文件。

import javafx.application.Application;
import javafx.stage.Stage;
public class Main extends Application{

    public static void main(String[] args){
        System.out.println("hej");
        launch();
    }

    @Override
    public void start(Stage stage){

    }

}

It seems to be something with javaFX. 似乎与javaFX有关。 I am using linux 我正在使用linux

These two tell the Java interpreter where the bytecode class files are. 这两个告诉Java解释器字节码类文件在哪里。 When you are getting the error: 'could not find or load main class' , try them. 当您收到错误消息: “找不到或加载主类”时 ,请尝试一下。

If your class file is saved in c:\\folder directory with MyJavaFxApp program name 如果您的类文件使用MyJavaFxApp程序名称保存在c:\\folder目录中

  1. java -cp c:\\folder MyJavaFxApp
  2. java -cp . MyJavaFxApp

It was something to do with different versions of Java, I essentially changed the default version to a newer one using this guide 这与Java的不同版本有关,我使用本指南将默认版本实质上更改为较新的版本。

http://ask.xmodulo.com/change-default-java-version-linux.html http://ask.xmodulo.com/change-default-java-version-linux.html

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM