我無法讓 OpenJFX 在我的項目中工作。我將該庫導入到我的 IntelliJ 項目中,它解決了所有構建錯誤,但是當我啟動我的程序時,什么也沒有發生。控制臺沒有給我任何輸出。該程序啟動,然后無限期運行,不顯示任何內容。當我停止程序時它說Process finished with exit code 130 (interrupted by signal 2: SIGINT)Main.javaimport javafx.application.Application;import javafx.fxml.FXMLLoader;import javafx.scene.Scene;import javafx.stage.Stage;public class Main extends Application { public static void main(String[] args) { } @Override public void start(Stage stage) throws Exception { stage.setTitle("Binary Clock"); stage.setScene(new Scene(FXMLLoader.load(getClass().getResource("clock_gui.fxml")))); stage.show(); }}ClockGui.java(作為控制器)import javafx.fxml.FXML;import javafx.scene.paint.Color;import javafx.scene.shape.Rectangle;public class ClockGui { @FXML private Rectangle ht8; public ClockGui(){ ht8.setFill(Color.rgb(225,250,30)); }}我在 Ubuntu 18.04.2 LTS 上。
1 回答

慕田峪9158850
TA貢獻1794條經驗 獲得超7個贊
你說你啟動了虛擬機,但它“什么也沒做”。這樣做的原因主要在于:
public static void main(String[] args) {
}
那是您應用程序的入口點,但您并沒有要求它調用您的應用程序類......
正如您可以從 (Javadoc]( https://openjfx.io/javadoc/12/javafx.graphics/javafx/application/Application.html#launch(java.lang.String...) ) 中讀到的那樣,這是啟動獨立應用程序所需的方法,通常從main.
只需添加:
public static void main(String[] args) {
launch(args);
}
添加回答
舉報
0/150
提交
取消