(Netbeans)缺少JavaFX运行时组件吗?

时间:2019-04-14 17:51:10

标签: javafx netbeans runtime-error

我正在使用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

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

1 个答案:

答案 0 :(得分:0)

如果您安装了带有 openJFX 的 JDK,您可以通过以下方式轻松修复:

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