当前位置: 首页 > 知识库问答 >
问题:

我试图用javafx做一个图,我得到了错误:JavaFX运行时组件丢失,需要运行这个应用程序

毋宪
2023-03-14

所以我对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”:”--模块路径/C:/Documents/javafx-sdk-11.0.2/lib--添加模块javafx.controls、javafx.fxml“,

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

msgstr"启动层初始化过程中发生错误java.nio.file.无效路径异常:非法字符

有什么解决办法吗?

共有1个答案

张权
2023-03-14

啊,我发现,我用来在vmarguments中添加模块的地址实际上是错误的,然后立即修复了它。

 类似资料: