sshahine / JFoenix

JavaFX Material Design Library
MIT License
6.27k stars 1.05k forks source link

Jfoenix runtime exception #1160

Open HuangLinBao opened 3 years ago

HuangLinBao commented 3 years ago

I created a javaFX project with maven and included Jfoenix latest dependency and everything.

I made the fxml file and run it with JFxtextfield and JFxPasswordfield and when I press run this thing happened

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: javafx.fxml.LoadException: 
/C:/Users/tariq/IdeaProjects/PCIapp/target/classes/com/PCIapp/primary.fxml

    at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2707)
    at javafx.fxml/javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2949)
    at javafx.fxml/javafx.fxml.FXMLLoader.processImport(FXMLLoader.java:2793)
    at javafx.fxml/javafx.fxml.FXMLLoader.processProcessingInstruction(FXMLLoader.java:2758)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2624)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
    at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2517)
    at com.PCIapp/com.PCIapp.App.loadFXML(App.java:32)
    at com.PCIapp/com.PCIapp.App.start(App.java:20)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    ... 1 more
Caused by: java.lang.ClassNotFoundException: com.jfoenix.controls.JFXPasswordField
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadTypeForPackage(FXMLLoader.java:3017)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:3006)
    at javafx.fxml/javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2947)
    ... 16 more
Exception running application com.PCIapp.App

and the thing that caught me and I am stuck with it is this part :

Caused by: java.lang.ClassNotFoundException: com.jfoenix.controls.JFXPasswordField
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadTypeForPackage(FXMLLoader.java:3017)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:3006)
    at javafx.fxml/javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2947)
    ... 16 more
Exception running application com.PCIapp.App

here is my Main File:

package com.PCIapp;

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

import java.io.IOException;

public class App extends Application {

    private static Scene scene;
    @Override
    public void start(Stage stage) throws IOException {
        scene = new Scene(loadFXML("primary"), 1280, 800);
        stage.setScene(scene);
        stage.setResizable(false);
        stage.show();
    }

    static void setRoot(String fxml) throws IOException {
        scene.setRoot(loadFXML(fxml));
    }

    private static Parent loadFXML(String fxml) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
        return fxmlLoader.load();
    }

    public static void main(String[] args) {
        launch();
    }

}

and here is the fxml :

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

<?import com.jfoenix.controls.JFXPasswordField?>
<?import com.jfoenix.controls.JFXTextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" opacity="0.6" prefHeight="800.0" prefWidth="1280.0" style="-fx-background-color: #F5F6FA;" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <ImageView fitHeight="634.0" fitWidth="1204.0" layoutX="38.0" layoutY="83.0" pickOnBounds="true" preserveRatio="true" rotate="-8.0">
         <image>
            <Image url="@PCI%20logoRYB.png" />
         </image></ImageView>
      <Pane layoutX="380.0" layoutY="140.0" prefHeight="521.0" prefWidth="520.0" style="-fx-background-color: #DFE4EA; -fx-border-radius: 20; -fx-background-radius: 20;">
         <children>
            <JFXTextField fx:id="Username" focusColor="#292f5f" labelFloat="true" layoutX="44.0" layoutY="96.0" prefHeight="69.0" prefWidth="432.0" promptText="Username" unFocusColor="#292f5f">
               <font>
                  <Font name="Segoe UI Bold" size="20.0" />
               </font>
            </JFXTextField>
            <JFXPasswordField fx:id="Password" focusColor="#292f5f" labelFloat="true" layoutX="44.0" layoutY="294.0" prefHeight="69.0" prefWidth="432.0" promptText="Password" unFocusColor="#292f5f">
               <font>
                  <Font name="Segoe UI Bold" size="20.0" />
               </font>
            </JFXPasswordField>
         </children>
      </Pane>
   </children>
</AnchorPane>

and here is the controller"it's pre-written" :

package com.PCIapp;

import java.io.IOException;
import javafx.fxml.FXML;

public class PrimaryController {

    @FXML
    private void switchToSecondary() throws IOException {
        App.setRoot("secondary");
    }
}

and the pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.PCIapp</groupId>
    <artifactId>PCIapp</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.jfoenix</groupId>
            <artifactId>jfoenix</artifactId>
            <version>9.0.10</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>15.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>15.0.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.4</version>
                <configuration>
                    <mainClass>com.PCIapp.App</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

can someone tell what;s the problem?

Ps: I am using InteliJ