0

Im new to Java and I keep getting an error in Intellij that it is having an issue with my start method.

I know the issue is because it doesn't like the path but I put the full path to the login.fxml file. I was following a tutorial but the path was exactly how mine is and the error went away.

Here is my code:

package sample;

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

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("/sample/view/login.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root, 700, 400));
        primaryStage.show();
    }


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

Here is my login.xml file code as well:


<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXPasswordField?>
<?import com.jfoenix.controls.JFXTextField?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="700.0" style="-fx-background-color: d32f2f;" xmlns="http://javafx.com/javafx/8.0" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.controller.LoginController">
    <children>
        <AnchorPane layoutY="72.0" prefHeight="328.0" prefWidth="700.0" style="-fx-background-color: #ffffff;">
            <children>
                <JFXTextField fx:id="loginUserName" focusColor="#424242" layoutX="214.0" layoutY="67.0" prefHeight="27.0" prefWidth="272.0" promptText="Username" unFocusColor="#ff6659" />
                <JFXPasswordField fx:id="loginPassword" focusColor="#424242" layoutX="214.0" layoutY="137.0" prefHeight="27.0" prefWidth="272.0" promptText="Password" unFocusColor="#ff6659" />
                <Label alignment="CENTER" layoutX="285.0" layoutY="14.0" prefHeight="17.0" prefWidth="130.0" text="Login" textFill="#6f6767">
                    <font>
                        <Font size="18.0" />
                    </font>
                </Label>
                <JFXButton fx:id="loginButton" layoutX="269.0" layoutY="193.0" prefHeight="27.0" prefWidth="163.0" style="-fx-background-color: #424242;" text="Login" textFill="#fffefe" />
            </children>
        </AnchorPane>
        <Label alignment="CENTER" layoutX="285.0" layoutY="14.0" prefHeight="17.0" prefWidth="130.0" text="TO DO" textFill="#fcfafa">
            <font>
                <Font size="36.0" />
            </font>
        </Label>
        <JFXButton fx:id="loginSignUpButton" layoutX="598.0" layoutY="14.0" prefHeight="27.0" prefWidth="88.0" style="-fx-background-color: #9a0007;" text="Sign Up" textFill="WHITE" />
    </children>
</AnchorPane>

and here is the error that im getting:

"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:473)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:372)
    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:945)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
    at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.NoClassDefFoundError: com/sun/javafx/css/converters/PaintConverter
    at com.jfoenix.controls.JFXTextField$StyleableProperties.<clinit>(JFXTextField.java:266)
    at com.jfoenix.controls.JFXTextField.<init>(JFXTextField.java:171)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
    at java.base/java.lang.Class.newInstance(Class.java:558)
    at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(FXMLLoader.java:1019)
    at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:754)
    at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3253)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3210)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3129)
    at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3122)
    at sample.Main.start(Main.java:13)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
Caused by: java.lang.ClassNotFoundException: com.sun.javafx.css.converters.PaintConverter
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
    ... 25 more
Exception running application sample.Main
"

Any ideas on how to fix?

ahern8
  • 13
  • 4
  • Please post your `login.fxml` code – vladwoguer Jun 07 '19 at 02:45
  • @vladwoguer Hi, I edited my post to add the login.fxml code – ahern8 Jun 07 '19 at 03:19
  • From your updated stack trace, your problem is here: `Caused by: java.lang.ClassNotFoundException: com.sun.javafx.css.converters.PaintConverter`. Apparently you are using [JFoenix](http://www.jfoenix.com/). Have you included the relevant details to your run configuration in Intellij? If your are using Maven, have you updated the `pom.xml`? If you are using java modules, have you updated the `module-info` file? Have you added relevant JARs to your CLASSPATH? – Abra Jun 07 '19 at 03:57

1 Answers1

0

This part of the stack trace you posted indicates what the problem is.

Caused by: java.lang.ClassNotFoundException: sample.controller.LoginController

From the javadoc for ClassNotFoundException

Thrown when an application tries to load in a class through its string name using:

  • The forName method in class Class.
  • The findSystemClass method in class ClassLoader.
  • The loadClass method in class ClassLoader.

but no definition for the class with the specified name could be found.

In other words file sample\controller\LoginController.class cannot be found.
Note that the above path is a relative path and it is relative to your app's working directory.
The working directory is the value of the System property "user.dir", as in

String workingDirectory = System.getProperty("user.dir");

So you can check why you are getting the exception.
Either there is no such file LoginController.class or it is in the wrong directory.

Abra
  • 19,142
  • 7
  • 29
  • 41
  • Hi, I did miss the LoginController class but I have fixed that and edited my post to include the most recent error. Fixing my class didnt fix the issue unfortunately. – ahern8 Jun 07 '19 at 03:20
  • Well, it fixed your initial problem, but obviously not all your problems, so it did help you progress towards a solution. – Abra Jun 07 '19 at 03:52