java “错误:无法找到或加载主类”JavaFX 终端

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30230219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 16:43:25  来源:igfitidea点击:

"Error: Could not find or load main class" JavaFX Terminal

javaubuntujavafxterminaljavafx-8

提问by user2590745

I'm using the following class from my JavaFX Tutorial:

我正在使用 JavaFX 教程中的以下类:

import javafx.application.Application;
import javafx.stage.Stage;

public class HelloFXApp extends Application {
    public static void main(String[] args) {
        // Launch the JavaFX application
        Application.launch(args);
    }

    @Override
    public void start(Stage stage) {
        stage.setTitle("Hello JavaFX Application");
        stage.show();
    }
}

I'm using Ubuntu and I have the correct path to my .java file in my Terminal..
When I type "javac HelloFXApp.java" it works fine and a new "HelloFXApp.class" file is created. but when I try "java HelloFXApp" I receive the following error:

我正在使用 Ubuntu,并且我的终端中有正确的 .java 文件路径
。但是当我尝试“java HelloFXApp”时,我收到以下错误:

Error: Could not find or load main class HelloFXApp

错误:无法找到或加载主类 HelloFXApp

I checked my Java version by typing "java -version" and it looks like I have the latest one:

我通过键入“java -version”检查了我的 Java 版本,看起来我有最新的版本:

java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) Server VM (build 25.45-b02, mixed mode)

Please tell me if I missed something! Thank you in advance..

如果我错过了什么,请告诉我!先感谢您..

采纳答案by ItachiUchiha

You are missing the packagewhile firing javacommand. (Implied from the comments, since it is not included in the question)

the package在发射java命令时失踪了。(从评论中暗示,因为它不包含在问题中)

After compiling, navigate back to src folderand append the package to your class name :

编译后,导航回src folder并将包附加到您的类名:

java com.jdojo.intro.HelloFXApp

回答by Sawsan SliiMarzouki Ep Jaouadi

Go and rename the project and it will work

去重命名项目,它会工作