(Netbeans) JavaFX 运行时组件丢失?

问题描述 投票:0回答:2

我正在使用 netbeans,并且我有这个 javaFX 代码,它应该创建一个折线图。该代码不是我的,我只是首先想让 javaFX 工作,然后我将编写我打算编写的类。

package javaapplication5;

import javafx.application.Application; 
import static javafx.application.Application.launch;
import javafx.scene.Group; 
import javafx.scene.Scene; 
import javafx.stage.Stage; 
import javafx.scene.chart.LineChart; 
import javafx.scene.chart.NumberAxis; 
import javafx.scene.chart.XYChart; 


public class LineGraph extends Application { 
   @Override 
   public void start(Stage stage) {
      //Defining the x axis             
      NumberAxis xAxis = new NumberAxis(1960, 2020, 10); 
      xAxis.setLabel("Years"); 

      //Defining the y axis   
      NumberAxis yAxis = new NumberAxis   (0, 350, 50); 
      yAxis.setLabel("No.of schools"); 

      //Creating the line chart 
      LineChart linechart = new LineChart(xAxis, yAxis);  

      //Prepare XYChart.Series objects by setting data 
      XYChart.Series series = new XYChart.Series(); 
      series.setName("No of schools in an year"); 

      series.getData().add(new XYChart.Data(1970, 15)); 
      series.getData().add(new XYChart.Data(1980, 30)); 
      series.getData().add(new XYChart.Data(1990, 60)); 
      series.getData().add(new XYChart.Data(2000, 120)); 
      series.getData().add(new XYChart.Data(2013, 240)); 
      series.getData().add(new XYChart.Data(2014, 300)); 

      //Setting the data to Line chart    
      linechart.getData().add(series);        

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

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

      //Setting title to the Stage 
      stage.setTitle("Line 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); 
   } 
}

此代码应该由所有帐户运行。但是当我执行它时,程序失败并出现以下错误:

Error: JavaFX runtime components are missing, and are required to run this application

我不确定发生了什么,但我需要让它正常工作。有什么想法吗?

javafx netbeans runtime-error
2个回答
1
投票

如果您安装了 openJFX 的 JDK,则可以通过以下方式轻松修复该问题:

右键单击您的项目 -> 属性 -> 运行 -> 在 VM 选项中添加以下内容: --module-path "OpenJFX 文件夹/lib 的路径" --add-modules javafx.base,javafx.controls,javafx.fxml,javafx.graphics


0
投票

我正在使用 jdk 11 并按照以下步骤操作

右键单击您的项目 -> 属性 -> 运行 -> 在 VM 选项中添加以下内容: --module-path "path to your OpenJFX folder/lib" --add-modules javafx.base,javafx.controls,javafx.fxml ,javafx.graphics

但仍然遇到同样的错误。

© www.soinside.com 2019 - 2024. All rights reserved.