【问题标题】:I'm trying to make a graph with javafx and I am getting the error: JavaFX runtime components are missing, and are required to run this application我正在尝试使用 javafx 制作图表,但出现错误:缺少 JavaFX 运行时组件,并且需要运行此应用程序
【发布时间】:2021-08-01 10:43:26
【问题描述】:

所以我对 javafx 还是很陌生,我正在为一些软件包苦苦挣扎(我认为)

@Override
public void start(Stage stage) throws Exception {
    // Defining the axes
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(
            FXCollections.<String>observableArrayList(Arrays.asList("Speed", "User rating", "Milage", "Safety")));
    xAxis.setLabel("category");

    NumberAxis yAxis = new NumberAxis();
    yAxis.setLabel("score");

    // Creating the Bar chart
    BarChart<String, Number> barChart = new BarChart<>(xAxis, yAxis);
    barChart.setTitle("Comparison between various cars");

    // Prepare XYChart.Series objects by setting data
    XYChart.Series<String, Number> series1 = new XYChart.Series<>();
    series1.setName("Fiat");
    series1.getData().add(new XYChart.Data<>("Speed", 1.0));
    series1.getData().add(new XYChart.Data<>("User rating", 3.0));
    series1.getData().add(new XYChart.Data<>("Milage", 5.0));
    series1.getData().add(new XYChart.Data<>("Safety", 5.0));

    XYChart.Series<String, Number> series2 = new XYChart.Series<>();
    series2.setName("Audi");
    series2.getData().add(new XYChart.Data<>("Speed", 5.0));
    series2.getData().add(new XYChart.Data<>("User rating", 6.0));
    series2.getData().add(new XYChart.Data<>("Milage", 10.0));
    series2.getData().add(new XYChart.Data<>("Safety", 4.0));

    XYChart.Series<String, Number> series3 = new XYChart.Series<>();
    series3.setName("Ford");
    series3.getData().add(new XYChart.Data<>("Speed", 4.0));
    series3.getData().add(new XYChart.Data<>("User rating", 2.0));
    series3.getData().add(new XYChart.Data<>("Milage", 3.0));
    series3.getData().add(new XYChart.Data<>("Safety", 6.0));

    // Setting the data to bar chart
    barChart.getData().addAll(series1, series2, series3);

    // Creating a Group object
    Group root = new Group(barChart);

    // Creating a scene object
    Scene scene = new Scene(root, 600, 400);

    // Setting title to the Stage
    stage.setTitle("Bar Chart");

    // Adding scene to the stage
    stage.setScene(scene);

    // Displaying the contents of the stage
    stage.show();
}

 public static void main(String[] args) {
    launch(args);
}

这是我创建条形图的示例代码,我收到错误“JavaFX 运行时组件丢失,需要运行此应用程序”。然后我在我的配置中添加了一个 vmargument。由于我使用vscode我输入了

"vmArgs": "--module-path /C:/Documents/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml",

进入launch.json。不过在那之后,我得到了错误

“初始化引导层java.nio.file.InvalidPathException时出错:Illegal char <:> at index 2: /C:/Documents/javafx-sdk-11.0.2/lib”

有什么解决办法吗?

【问题讨论】:

    标签: java spring javafx error-handling runtime


    【解决方案1】:

    啊,我想通了,我在vmarguments中添加模块的地址实际上是错误的,然后立即修复了。

    【讨论】:

      猜你喜欢
      • 2021-07-02
      • 1970-01-01
      • 2013-01-17
      • 2022-01-17
      • 1970-01-01
      • 2019-02-07
      • 2020-04-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多