0

I am new to javafx.Currently I am developing a miniproject.I am designing it's UI in scene builder-18.0.0.

I have added fontawesomefx jar file to reference library.

When I use fontawesomefx icons to my project, it's shows the following Exception.If I remove the icons, the program runs fine.

Result

Exception in Application start method
java.lang.reflect.InvocationTargetExceptionf
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
        at java.base/java.lang.reflect.Method.invoke(Method.java:577)
        at javafx.graphics@18.0.2/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
        at javafx.graphics@18.0.2/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:577)
        at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1081)
Caused by: java.lang.RuntimeException: Exception in Application start method
        at javafx.graphics@18.0.2/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
        at javafx.graphics@18.0.2/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.NoClassDefFoundError: com/sun/javafx/css/parser/CSSParser
        at de.jensd.fx.glyphs.GlyphIcon.<clinit>(GlyphIcon.java:49)
        at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
        at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1160)
        at java.base/jdk.internal.reflect.MethodHandleAccessorFactory.ensureClassInitialized(MethodHandleAccessorFactory.java:300)
        at java.base/jdk.internal.reflect.MethodHandleAccessorFactory.newConstructorAccessor(MethodHandleAccessorFactory.java:103)
        at java.base/jdk.internal.reflect.ReflectionFactory.newConstructorAccessor(ReflectionFactory.java:236)
        at java.base/java.lang.reflect.Constructor.acquireConstructorAccessor(Constructor.java:546)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:496)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:483)
        at javafx.fxml@18.0.2/javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(FXMLLoader.java:1020)
        at javafx.fxml@18.0.2/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:757)
        at javafx.fxml@18.0.2/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2808)
        at javafx.fxml@18.0.2/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2634)
        at javafx.fxml@18.0.2/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
        at javafx.fxml@18.0.2/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2516)
        at App.start(App.java:19)
        at javafx.graphics@18.0.2/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
        at javafx.graphics@18.0.2/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
        at javafx.graphics@18.0.2/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
        at javafx.graphics@18.0.2/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
        at javafx.graphics@18.0.2/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
        at javafx.graphics@18.0.2/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at javafx.graphics@18.0.2/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
        ... 1 more
Caused by: java.lang.ClassNotFoundException: com.sun.javafx.css.parser.CSSParser
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        ... 25 more
Exception running application App

My Fxml code

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

<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="609.0" prefWidth="932.0" styleClass="holder" stylesheets="@TableStyle.css" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <Pane layoutY="7.0" prefHeight="28.0" prefWidth="932.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
         <children>
            <Label layoutX="17.75" layoutY="3.0" styleClass="app-title" text="Hello Tables" textFill="WHITE">
               <font>
                  <Font size="15.0" />
               </font>
            </Label>
         </children>
      </Pane>
      <AnchorPane layoutX="14.0" layoutY="28.0" prefHeight="200.0" prefWidth="256.0" styleClass="sideview" AnchorPane.bottomAnchor="7.0" AnchorPane.leftAnchor="7.0" AnchorPane.topAnchor="28.0">
         <children>
            <StackPane alignment="CENTER_RIGHT" layoutX="17.0" layoutY="48.0" AnchorPane.leftAnchor="35.6" AnchorPane.topAnchor="45.0">
               <children>
                  <TextField promptText="Search here" styleClass="txt-field" />
               </children>
            </StackPane>
            <ListView layoutX="28.0" layoutY="131.0" prefHeight="200.0" prefWidth="200.0" styleClass="listview" AnchorPane.bottomAnchor="110.0" AnchorPane.topAnchor="125.0" />
            <StackPane layoutX="17.0" layoutY="514.0" prefHeight="30.0" prefWidth="222.0" AnchorPane.bottomAnchor="29.600000000000023">
               <children>
                  <Button maxHeight="-Infinity" maxWidth="-Infinity" mnemonicParsing="false" prefHeight="30.0" prefWidth="145.0" styleClass="btn-new-table" />
                  <Label styleClass="txt-new-table" text="NEW TABLE" />
               </children>
            </StackPane>
            <FontAwesomeIconView layoutX="111.0" layoutY="293.0" />
         </children>
      </AnchorPane>
      <AnchorPane layoutX="316.0" layoutY="38.0" prefHeight="200.0" prefWidth="200.0" styleClass="sideview" AnchorPane.bottomAnchor="7.0" AnchorPane.leftAnchor="267.0" AnchorPane.rightAnchor="7.0" AnchorPane.topAnchor="28.0">
         <children>
            <Label layoutX="27.0" layoutY="69.0" text="NOTES" AnchorPane.leftAnchor="27.0" AnchorPane.topAnchor="69.0">
               <font>
                  <Font name="System Bold" size="21.0" />
               </font>
            </Label>
            <StackPane layoutX="27.0" layoutY="126.0" prefHeight="353.0" prefWidth="611.0" AnchorPane.bottomAnchor="96.0" AnchorPane.leftAnchor="27.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="125.0">
               <children>
                  <Label alignment="TOP_LEFT" prefHeight="75.0" prefWidth="214.0" styleClass="txt-no-table" text="NO TABLE SELECTED" textAlignment="CENTER" StackPane.alignment="CENTER">
                     <font>
                        <Font name="Roboto" size="16.799999237060547" />
                     </font>
                  </Label>
                  <AnchorPane prefHeight="200.0" prefWidth="200.0">
                     <children>
                        <Pane layoutY="41.0" prefHeight="200.0" prefWidth="200.0" styleClass="table-holder" AnchorPane.bottomAnchor="25.0" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="106.5" AnchorPane.topAnchor="2.0" />
                        <TableView prefHeight="353.0" prefWidth="503.0" AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="95.0" AnchorPane.topAnchor="0.0">
                          <columns>
                            <TableColumn prefWidth="75.0" text="NAME" />
                            <TableColumn prefWidth="75.0" text="AGE" />
                          </columns>
                           <columnResizePolicy>
                              <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
                           </columnResizePolicy>
                        </TableView>
                        <VBox alignment="CENTER" layoutX="556.0" layoutY="27.0" prefHeight="327.0" prefWidth="48.0" AnchorPane.bottomAnchor="27.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="0.0">
                           <children>
                              <FlowPane alignment="CENTER" orientation="VERTICAL" prefHeight="315.0" prefWidth="55.0" styleClass="toolbar" />
                           </children>
                        </VBox>
                     </children>
                  </AnchorPane>
               </children></StackPane>
            <FlowPane alignment="CENTER_LEFT" hgap="10.0" layoutX="27.0" layoutY="432.0" prefHeight="102.0" prefWidth="490.0" vgap="10.0" AnchorPane.bottomAnchor="1.0" AnchorPane.leftAnchor="27.0" AnchorPane.rightAnchor="141.0">
               <children>
                  <TextField promptText="Search here" styleClass="txt-field" />
               </children>
            </FlowPane>
            <StackPane layoutX="422.0" layoutY="499.0" maxHeight="-Infinity" prefHeight="30.0" prefWidth="153.0" AnchorPane.bottomAnchor="30.0" AnchorPane.rightAnchor="120.0">
               <children>
                  <Button maxHeight="-Infinity" maxWidth="-Infinity" mnemonicParsing="false" prefHeight="30.0" prefWidth="131.0" styleClass="btn-new-table" />
                  <Label styleClass="txt-new-table" text="ADD ROW" />
               </children>
            </StackPane>
         </children>
      </AnchorPane>
   </children>
</AnchorPane>

Java(Main class)


import java.io.IOException;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class App extends Application{
   
    @Override
    public void start(Stage stage) throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("TableAppInterface.fxml"));
        System.out.println("hi");
        Parent root = null;
        try {
            root = loader.load();
        } catch (IOException e) {
            
            e.printStackTrace();
        }
        Scene scene = new Scene(root);

        stage.setScene(scene);
        //stage.initStyle(StageStyle.TRANSPARENT);
        stage.setTitle("Tables");
        stage.show();
        
    }
    
    public static void main(String[] args) throws Exception {
        launch(args);
    }

}

launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Launch Current File",
            "request": "launch",
            "mainClass": "${file}"
        },
        {
            "type": "java",
            "name": "Launch App",
            "request": "launch",
            "mainClass": "App",
            "projectName": "TableApp_e71931e0",
            "vmArgs": "--module-path \"C:/Program Files/Java/javafx-sdk-18.0.2/lib\" --add-modules javafx.controls,javafx.fxml"
        }
    ]

}

I also tried with the following vmArgs

"vmArgs": "--module-path \"C:/Program Files/Java/javafx-sdk-18.0.2/lib\" --add-modules javafx.controls,javafx.fxml \ --add-opens javafx.graphics/javafx.css=ALL-UNNAMED"

I also visited this post and used fontawesomfx 8.4.but it didn't work.It shows the same exception.

Currently I am using java 18(jdk-18.0.2) and javafx-sdk-18.0.2 and SceneBuilder-18.0.0 and fontawesomefx 8.9 jar.I use visual studio code.I am not using any built tools for my project.

NOTE:If I run the code without any fontawesomefx icons, my code works fine.

I have been searching the solution for this problem for an entire day.Please explain me what is the problem and how to solve it.I want to use fontawesomeicons in my project.How to do it?

Thank you

  • 1
    The [`CSSParser`](https://openjfx.io/javadoc/19/javafx.graphics/javafx/css/CssParser.html) class was moved from the private `com.sun.javafx` packages to the public `javafx.css` package in version 9 of JAvaFX. The FontAwesomeFX version you are using appears to be assuming you are using JavaFX 8 or earlier. – James_D Oct 31 '22 at 18:19
  • 2
    I recommend using [Ikonli](https://kordamp.org/ikonli/#_installing_2) instead. – jewelsea Oct 31 '22 at 18:54

1 Answers1

0

You need to upgrade the version of fontawesomefx you are using to be compatible with your java version.

See the answer to this question, I believe your problem is the same as this person was seeing.

Ben Borchard
  • 631
  • 3
  • 9