【发布时间】:2021-01-19 02:02:03
【问题描述】:
我在 Windows10 eclipse 上使用 JavaSE-1.8 工作,我刚刚将我的 SceneBuilder 与 javaFX 项目连接起来并添加了一个按钮 - 没有别的。我尝试运行该项目以查看它(第一次在这里使用 javafx!)并且我不断收到此错误:错误:JavaFX 运行时组件丢失,并且需要运行此应用程序 我尝试重新启动我的计算机,运行一个新项目......等等没有任何效果:(
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
BorderPane root = new BorderPane();
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
screenshot of my file and error message
这是 .fxml 代码
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="191.0" prefWidth="259.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/15.0.1">
<children>
<Button layoutX="91.0" layoutY="82.0" mnemonicParsing="false" text="Select File..." />
</children>
</AnchorPane>
【问题讨论】: