fxml对象不能是静态的

时间:2016-03-20 09:28:20

标签: javafx static fxml

我将在另一个类的主类中运行一个函数。所以它的方法必须是静态的,因此它内部的所有变量也应该是静态的。这个方法我修改的图表是从由scenebuilder创建的FXML导入的。当我将图表对象添加为静态对象时,程序崩溃时出现以下跟踪错误。

问题是什么:这就是我为此所做的:

@FXML
private Menu comPortsMenu;
@FXML
private   LineChart<Number,Number> chart1;
@FXML
private  LineChart<Number,Number> chart2;
@FXML
private  LineChart<Number,Number> chart3;
@FXML
private  LineChart<Number,Number> chart4;
public static    ArrayList<XYChart.Series<Number, Number>> series;

这是从第一个运行方法的secound类

 private void applyConfig(ActionEvent actionEvent) throws IOException {
   int x1=fullNameTotelemID.get(boxMap.get(chartOption1.getSelectionModel().getSelectedIndex()));
   int x2=fullNameTotelemID.get(boxMap.get(chartOption2.getSelectionModel().getSelectedIndex()));
   int x3=fullNameTotelemID.get(boxMap.get(chartOption3.getSelectionModel().getSelectedIndex()));
   int x4=fullNameTotelemID.get(boxMap.get(chartOption4.getSelectionModel().getSelectedIndex()));
   FXMLDocumentController.desiredCharts.set(0, x1);
   FXMLDocumentController.desiredCharts.set(0, x2);
   FXMLDocumentController.desiredCharts.set(0, x3);
   FXMLDocumentController.desiredCharts.set(0, x4);
   FXMLDocumentController.loadCharts();
    closeButtonAction(actionEvent);
}

这是主类

中的静态方法
 public static void loadCharts(){
     chart1.getData().removeAll();
            chart2.getData().removeAll();
            chart3.getData().removeAll();
            chart4.getData().removeAll();
            chart1.getData().add(series.get(desiredCharts.get(0)));
            chart2.getData().add(series.get(desiredCharts.get(1)));
            chart3.getData().add(series.get(desiredCharts.get(2)));
            chart4.getData().add(series.get(desiredCharts.get(3)));
            chart1.setTitle(chartOptions.get(desiredCharts.get(0)));
    chart2.setTitle(chartOptions.get(desiredCharts.get(1)));
    chart3.setTitle(chartOptions.get(desiredCharts.get(2)));
    chart4.setTitle(chartOptions.get(desiredCharts.get(3)));
}

这是跟踪错误:

 Executing /Users/apple/NetBeansProjects/JavaFXApplication6/dist/run1812641360/JavaFXApplication6.jar using platform /Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home/jre/bin/java
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException: 
     file:/Users/apple/NetBeansProjects/JavaFXApplication6/dist/run1812641360/JavaFXApplication6.jar!/javafxapplication6/FXMLDocument.fxml

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at javafxapplication6.JavaFXApplication6.start(JavaFXApplication6.java:22)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Caused by: java.lang.NullPointerException
at javafxapplication6.FXMLDocumentController.initialize(FXMLDocumentController.java:441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
... 14 more
Exception running application javafxapplication6.JavaFXApplication6
Java Result: 1

0 个答案:

没有答案