I am in the process of moving my JavaFX project from Java 8 to Java 11, JavaFX 17 for the past week or so. I also moved from Scenebuilder 8.5 to Scenebuilder JavaFX Version: 20.0.1. All in all it has been reasonably smooth, however I am facing a confusing error that I cannot seem to solve.
Instances of `javafx.scene.chart.LineChart` cannot be created by FXML loader.
When I changed the Java version of my project to Java 11, and imported the JavaFX 17 library to my project, The LineChart
I am using in my project began throwing an error I had never seen before in the FXML Document file. It is a 330 line file so I will only include the relevant parts:
<?import javafx.scene.chart.CategoryAxis?>
<?import javafx.scene.chart.LineChart?>
<?import javafx.scene.chart.NumberAxis?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Line?>
<LineChart fx:id="chartDashboardLineChart" layoutX="5.0" layoutY="10.0" prefHeight="233.0" prefWidth="870.0" title="Monthly Sales">
<xAxis>
<CategoryAxis side="BOTTOM" fx:id="x" />
</xAxis>
<yAxis>
<NumberAxis fx:id="y" side="LEFT" />
</yAxis>
</LineChart>
The error is displayed under the line where the LineChart chartDashboardLineChart is declared. There are also two new errors which read: Class javafx.scene.chart.LineChart
does not support property xAxis
(and the same for yAxis
). These two errors seem less worrying to me than the FXML Loader error above.
I will also include the relevant lines of code from my project, although I believe it is more likely that the error lies within the FXML Document. Here is the Java Code (this is split across 2 different classes: Class: LineCharts.java
And another class, this one too large to post in its entirety called DashboardController.java, Here are the relevant parts of the DashboardController class:
@FXML
private LineChart<?, ?> chartDashboardLineChart;
@FXML
private CategoryAxis x;
@FXML
private NumberAxis y;
LineCharts LC = new LineCharts();
//later on in the initialize area of the code
//Call the initializeLineChart method and pass the line chart as an argument
LC.generateDashboardLineChart(chartDashboardLineChart);
I have tried numerous things to try and fix this issue, but with no success. It seems it is a rare issue to have as there is little to no information that I could find online.
I appreciate any bit of help or any theories as to what is causing my issue, and how to solve it. Thank you!