0

I made some changes to the file analyseAccident.fxml in Scenebuilder, then saved them. Closed it, renamed the file to analyzeAccident.fxml, execution of everything works fine but scenebuilder now throws a error when trying to open it. Opening other files works.

What seems to be the Cause of Problem in this specific File?

Trying to open it in IntelliJ's integrated Scenebuilder just shows this Line, which again makes me come to the conclusion that using Java 17 might be the Problem, but if so, setting the CustomBarChart to a normal BarChart from JavaFX should fix it, which it doesn't.

java.lang.UnsupportedClassVersionError: com/pichlmayr/unfallmeldung/CustomBarChart has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0


Error

java.io.IOException: javafx.fxml.LoadException: 
/C:/Users/mpich/IdeaProjects/Unfallmeldung/src/main/resources/com/pichlmayr/unfallmeldung/analyzeAccidents.fxml

    at com.oracle.javafx.scenebuilder.kit.fxom.FXOMLoader.load(FXOMLoader.java:101)
    at com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.<init>(FXOMDocument.java:91)
    at com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.<init>(FXOMDocument.java:108)
    at com.oracle.javafx.scenebuilder.kit.editor.EditorController.updateFxomDocument(EditorController.java:2560)
    at com.oracle.javafx.scenebuilder.kit.editor.EditorController.setFxmlTextAndLocation(EditorController.java:763)
    at com.oracle.javafx.scenebuilder.app.DocumentWindowController.loadFromFile(DocumentWindowController.java:389)
    at com.oracle.javafx.scenebuilder.app.SceneBuilderApp.performOpenFiles(SceneBuilderApp.java:668)
    at com.oracle.javafx.scenebuilder.app.SceneBuilderApp.performOpenFile(SceneBuilderApp.java:604)
    at com.oracle.javafx.scenebuilder.app.SceneBuilderApp.performControlAction(SceneBuilderApp.java:206)
    at com.oracle.javafx.scenebuilder.app.menubar.MenuBarController$ApplicationControlActionController.perform(MenuBarController.java:1778)
    at com.oracle.javafx.scenebuilder.app.menubar.MenuBarController.handleOnActionMenu(MenuBarController.java:1222)
    at com.oracle.javafx.scenebuilder.app.menubar.MenuBarController.lambda$new$4(MenuBarController.java:1216)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
    at javafx.base/javafx.event.Event.fireEvent(Unknown Source)
    at javafx.controls/javafx.scene.control.MenuItem.fire(Unknown Source)
    at javafx.controls/com.sun.javafx.scene.control.ContextMenuContent$MenuItemContainer.doSelect(Unknown Source)
    at javafx.controls/com.sun.javafx.scene.control.ContextMenuContent$MenuItemContainer.lambda$createChildren$12(Unknown Source)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
    at javafx.base/javafx.event.Event.fireEvent(Unknown Source)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Unknown Source)
    at javafx.graphics/javafx.scene.Scene.processMouseEvent(Unknown Source)
    at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(Unknown Source)
    at java.base/java.security.AccessController.doPrivileged(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown Source)
    at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(Unknown Source)
    at javafx.graphics/com.sun.glass.ui.View.notifyMouse(Unknown Source)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)
Caused by: javafx.fxml.LoadException: 
/C:/Users/mpich/IdeaProjects/Unfallmeldung/src/main/resources/com/pichlmayr/unfallmeldung/analyzeAccidents.fxml

    at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
    at javafx.fxml/javafx.fxml.FXMLLoader.importClass(Unknown Source)
    at javafx.fxml/javafx.fxml.FXMLLoader.processImport(Unknown Source)
    at javafx.fxml/javafx.fxml.FXMLLoader.processProcessingInstruction(Unknown Source)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml/javafx.fxml.FXMLLoader.load(Unknown Source)
    at com.oracle.javafx.scenebuilder.kit.fxom.FXOMLoader.load(FXOMLoader.java:96)
    ... 52 more
Caused by: java.lang.ClassNotFoundException: com.pichlmayr.unfallmeldung.CustomBarChart
    at java.base/java.lang.ClassLoader.findClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadTypeForPackage(Unknown Source)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadType(Unknown Source)
    ... 58 more

analyzeAccident.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.chart.BarChart?>
<?import javafx.scene.chart.CategoryAxis?>
<?import javafx.scene.chart.NumberAxis?>
<?import javafx.scene.chart.StackedBarChart?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.MenuButton?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.layout.AnchorPane?>

<?import com.pichlmayr.unfallmeldung.CustomBarChart?>
<AnchorPane fx:id="mainAnchor" prefHeight="800.0" prefWidth="1200.0" styleClass="mainAnchor" stylesheets="@styleshees.css" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.pichlmayr.unfallmeldung.AnalyzeAccident">
    <children>
        <CustomBarChart fx:id="course" layoutX="25.0" layoutY="70.0" prefHeight="720.0" prefWidth="1161.0" visible="false">
            <xAxis>
                <CategoryAxis fx:id="Category" side="BOTTOM" />
            </xAxis>
            <yAxis>
                <NumberAxis fx:id="Number" side="LEFT" />
            </yAxis>
        </CustomBarChart>
        <CustomBarChart fx:id="courseTimespan" layoutX="25.0" layoutY="70.0" prefHeight="710.0" prefWidth="1161.0" visible="false">
            <xAxis>
                <CategoryAxis fx:id="CategoryTimespan" side="BOTTOM" />
            </xAxis>
            <yAxis>
                <NumberAxis fx:id="NumberTimespan" side="LEFT" />
            </yAxis>
        </CustomBarChart>
        <MenuButton layoutX="24.0" layoutY="14.0" mnemonicParsing="false" styleClass="actionButton" stylesheets="@styleshees.css" text="Auswertungjahr">
            <items>
                <MenuItem mnemonicParsing="false" onAction="#onYearAll" text="Alle" />
                <MenuItem mnemonicParsing="false" onAction="#onYearTimespan" text="2019-2022" />
                <MenuItem mnemonicParsing="false" onAction="#onYear2019" text="2019" />
                <MenuItem mnemonicParsing="false" onAction="#onYear2020" text="2020" />
                <MenuItem mnemonicParsing="false" onAction="#onYear2021" text="2021" />
                <MenuItem mnemonicParsing="false" onAction="#onYear2022" text="2022" />
            </items>
        </MenuButton>
        <MenuButton layoutX="240.0" layoutY="14.0" mnemonicParsing="false" styleClass="actionButton" stylesheets="@styleshees.css" text="Auswertung">
            <items>
                <MenuItem mnemonicParsing="false" onAction="#perMonth" text="Unfälle pro Monat" />
                <MenuItem mnemonicParsing="false" onAction="#perWeekday" text="nach Wochentag" />
                <MenuItem mnemonicParsing="false" onAction="#perEmployee" text="nach Arbeitnehmerverhältnis" />
                <MenuItem mnemonicParsing="false" onAction="#perAccidentType" text="nach Unfallart" />
                <MenuItem mnemonicParsing="false" onAction="#perLocation" text="nach Unfallort" />
                <MenuItem mnemonicParsing="false" onAction="#perAccidentCause" text="nach Unfallursache" />
                <MenuItem mnemonicParsing="false" onAction="#perInjuryType" text="nach Art der Verletzung" />
                <MenuItem mnemonicParsing="false" onAction="#perInjuredBodyPart" text="nach Verletztem Körperteil" />
            </items>
        </MenuButton>
        <Button fx:id="export" layoutX="412.0" layoutY="14.0" mnemonicParsing="false" onAction="#onExport" styleClass="actionButton" stylesheets="@styleshees.css" text="Exportieren" />
        <Button fx:id="back" layoutX="1099.0" layoutY="14.0" mnemonicParsing="false" onAction="#onBack" styleClass="actionButton" stylesheets="@styleshees.css" text="Zurück" />
    </children>
</AnchorPane>

CustomBarChart.java

package com.pichlmayr.unfallmeldung;

import javafx.beans.NamedArg;
import javafx.scene.Node;
import javafx.scene.chart.Axis;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.scene.text.TextFlow;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class CustomBarChart<X, Y> extends BarChart<X, Y> {
    Map<Node, TextFlow> nodeMap = new HashMap<>();

    public CustomBarChart() {
        super((Axis<X>) new CategoryAxis(), (Axis<Y>) new NumberAxis());
    }

    public CustomBarChart(@NamedArg("xAxis") Axis xAxis, @NamedArg("yAxis") Axis yAxis) {
        super(xAxis, yAxis);
        this.setBarGap(0.0);
    }

    @Override
    protected void seriesAdded(Series<X, Y> series, int seriesIndex) {
        super.seriesAdded(series, seriesIndex);
        for (int j = 0; j < series.getData().size(); j++) {

            Data<X, Y> item = series.getData().get(j);
            if (!Objects.equals(item.getYValue().toString(), "0.0")) {
                Text text = new Text(item.getYValue().toString());
                text.setStyle("-fx-font-family: Arial;");
                text.setStyle("-fx-font-size: 8pt;");

                TextFlow textFlow = new TextFlow(text);
                textFlow.setTextAlignment(TextAlignment.CENTER);

                nodeMap.put(item.getNode(), textFlow);
                this.getPlotChildren().add(textFlow);

            }
        }
    }

    @Override
    protected void seriesRemoved(final Series<X, Y> series) {
        for (Node bar : nodeMap.keySet()) {
            Node text = nodeMap.get(bar);
            this.getPlotChildren().remove(text);
        }

        nodeMap.clear();

        super.seriesRemoved(series);
    }

    @Override
    protected void layoutPlotChildren() {
        super.layoutPlotChildren();
        for (Node bar : nodeMap.keySet()) {

            TextFlow textFlow = nodeMap.get(bar);

            if (bar.getBoundsInParent().getHeight() > 30) {
                ((Text) textFlow.getChildren().get(0)).setFill(Color.BLACK);
                textFlow.resize(bar.getBoundsInParent().getWidth(), 200);
                textFlow.relocate(bar.getBoundsInParent().getMinX(), bar.getBoundsInParent().getMinY() + 10);
            } else {
                ((Text) textFlow.getChildren().get(0)).setFill(Color.BLACK);
                textFlow.resize(bar.getBoundsInParent().getWidth(), 200);
                textFlow.relocate(bar.getBoundsInParent().getMinX(), bar.getBoundsInParent().getMinY() - 20);
            }
        }
    }
}
Matze._
  • 77
  • 11
  • 1
    `Caused by: java.lang.ClassNotFoundException: com.pichlmayr.unfallmeldung.CustomBarChart` Is something wrong in `CustomBarChart`? – SedJ601 Mar 27 '22 at 06:14
  • Does Scenebuilder support Java 17? Maybe that's the Problem? "You can use this Scene Builder version together with Java 11 and higher." – Matze._ Mar 27 '22 at 06:54
  • Just a guess. Looking at `analyzeAccidents.fxml` from the second line in your error message and `fx:controller="com.pichlmayr.unfallmeldung.AnalyzeAccident"`. Could your `FXML` name having the lowercase "a" be the issue? Also `Accident` is missing an "s". – SedJ601 Mar 27 '22 at 07:06
  • Tried changing it already, error still there. Before it was named analyseAccident and the Controller was the same Name as now (AnalyzeAccident), which worked. – Matze._ Mar 27 '22 at 09:06
  • Maybe you should show the code for the CustomBarChartClass – Jawad El Fou Mar 27 '22 at 15:25
  • 1
    Did you import a jar containing that class to scenebuilder? – Jawad El Fou Mar 27 '22 at 15:26
  • 1
    Try following the steps in https://stackoverflow.com/questions/30063792/adding-a-custom-component-to-scenebuilder-2-0 before loading the FXML referencing the custom class – James_D Mar 27 '22 at 15:49
  • Please edit the question to add explanatory info and code and delete the comments. Don’t use comments and pasteboard for that. Put the comments in the question with the additional code as text formatted as code. Error messages also as text formatted as code. Otherwise it is just illegible and harder to follow. Provide a [mcve] for debugging help. – jewelsea Mar 27 '22 at 16:54

0 Answers0