Fxmlloader load ошибка

I can not figure out for the life of me the problem with this code. I have done research on many similar questions here, addressing whether the directories were correct, possible wrong function calls etc.

I am hoping someone can help me out. Everything is in a file called login in an app called loginapp.

Here is Login.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package login;

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


public class Login extends Application   {

    @Override
    public void start(Stage stage) throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("Login.fxml"));
        Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("Login.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("Fracken");
        stage.show();
    }
}

Here is Login.fxml

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

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" prefHeight="317.0" prefWidth="326.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="login.Login">
   <children>
      <TextField fx:id="txtUsername" layoutX="110.0" layoutY="45.0" promptText="Username" />
      <PasswordField fx:id="txtPassword" layoutX="110.0" layoutY="115.0" promptText="Password" />
      <Button fx:id="btnLogin" layoutX="110.0" layoutY="184.0" mnemonicParsing="false" onAction="btnLoginAction" text="Login" />
      <Button fx:id="btnReset" layoutX="232.0" layoutY="184.0" mnemonicParsing="false" onAction="btnResetAction" text="Reset" />
      <Label fx:id="lblMessage" layoutX="110.0" layoutY="236.0" prefHeight="31.0" prefWidth="187.0" />
   </children>
</AnchorPane>

I am sure the issue is with

Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("Login.fxml"));

I get this error.

Executing C:\Users\David\Desktop\Java Project\loginapp\dist\run122343396\loginapp.jar using platform C:\Program Files\Java\jdk1.8.0_111\jre/bin/java
Exception in Application start method
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: Location is required.
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
    at login.Login.start(Login.java:23)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    ... 1 more
Java Result: 1

Please help me, I have looked at other’s similar issues on here but no solutions worked.

  1. Reasons Causing the JavaFX FXML Load Exception
  2. Solution to the JavaFX FXML Load Exception

Solution to the JavaFX FXML Load Exception

This tutorial educates about the reasons causing the JavaFX FXML load exception and provides a quick solution.

Reasons Causing the JavaFX FXML Load Exception

The first reason for getting the JavaFX FXML load exception is when the path to an FXML file is not specified correctly to a loader. The path /fxml/view.fxml refers to a file view.fxml in a folder named fxml which resides in the resources folder, i.e., on the classpath.

The getClass().getResource() call invokes an object classloader at runtime, which searches for the classpath for a resource passed to it. In this way, it will find the fxml folder and view.fxml file inside that folder.

The second reason can be having a mismatched component ID which means we may have updated a component ID in our Controller file but forgot to change that ID on the FXML file (or vice-versa). In this case, the Controller would not be able to link that component on the view.fxml file.

See the following chunk to have a clear understanding.

On the Controller File:

On the FXML View File:

Following is the solution to both of these reasons.

Solution to the JavaFX FXML Load Exception

To run this application, we are using Java 18, JavaFX 13, and NetBeans IDE version 13. You may use all of them as per your choice.

Example Code (view.fxml file, the view file):

<!--Step1: XML declaration-->
<?xml version="1.0" encoding="UTF-8"?>

<!--Step 2: import necessary java types in FXML-->

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>

<!--Step 3: specify the FXML namespace-->

<AnchorPane prefHeight="300.0" prefWidth="400.0"
xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.mycompany.javafx_fxml_loadexception.viewController">

    <!--Step 4: layout pane have children-->
    <children>
        <Button fx:id="btTest" layoutX="170.0"
        layoutY="208.0" mnemonicParsing="false"
        onAction="#onBtTestAction" text="Button" />

        <Label layoutX="167.0" layoutY="126.0" text="Cick here!" />
   </children>

</AnchorPane>

Following is the step-by-step explanation of the above code.

  • We write an XML declaration by describing the version and encoding.
  • Import all the necessary Java types in FXML.
  • We use the AnchorPane tag to declare the fx namespace prefix. This tag permits the child nodes’ edges to be anchored to the offset from an edge of the anchor pane.

    If there is padding or border in the anchor pane, then the offsets would be measured from those insets’ inside edges. The AnchorPane tag has various properties listed below with a brief explanation.

    • The prefHeight and prefWidth properties can be used to override the region’s computed preferred height and width.

    • In FXML, the fx:controller is used to specify the controller on a root element. Remember that we are allowed to have one controller per FXML document and must be specified on the root element.

      What is the root element in this code? The AchnorPane tag is the root element for this code example which is a top-level object in an object graph of the FXML document.

      All the UI elements will be added to this element. Further, we also need to know the rules a controller must satisfy; these rules are listed below:

      • A controller is instantiated by the FXML loader.
      • A controller must have the public no-args constructor. The FXML loader would be unable to instantiate it if it is not there, resulting in an exception at load time.
      • A controller can contain accessible functions that can also be specified as the event handlers in the FXML.
      • The FXML controller automatically looks for a controller’s accessible instance variable(s). If the accessible instance variable’s name matches an element’s fx:id attribute, an object reference from the FXML will automatically be copied into a controller instance variable.

      This feature will make UI elements’ references in the FXML accessible to the controller. Then, the controller would be able to use them.

    • A controller can also access the initialize() function, which must not accept arguments and return the void type. Once the FXML document’s loading process is complete, the FXML loader calls the initialize() function.

  • In FXML, the layout panes contain the children as their child elements. Considering the project requirements, we can add labels, buttons, and other elements.

Example Code (viewController.java class, the controller class):

//Step 1: replace this package name with your package name
package com.mycompany.javafx_fxml_loadexception;

//Step 2: import necessary libraries
import javafx.fxml.FXML;
import javafx.scene.control.Button;

// Step 3: viewController class
public class viewController {

    //define button
    @FXML
    private Button btTest;

    //define the action when the button is clicked
    @FXML
    public void onBtTestAction() {
        System.out.println("CLICK");
    }//end onBtTestAction method

}//end viewController class

The viewController.java class is a controller class that uses the @FXML annotation on some members. Remember that this annotation can be used on constructors and classes.

Using this annotation, we specify that the FXML loader can easily access this member even if that is private. We do not need to use the @FXML annotation if the FXML loader uses a public member.

However, using @FXML for a public member does not raise any error. So, it is good to annotate every member.

The following FXML sets the onBtTestAction() function of a controller class as an event handler for the Button:

<Button fx:id="btTest" layoutX="170.0" layoutY="208.0" mnemonicParsing="false"         onAction="#onBtTestAction" text="Button" />

Example Code (App.java class, the main class):

//Step 1: replace the package name with your package name
package com.mycompany.javafx_fxml_loadexception;

//Step 2: import necessary libraries
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

//Step 3: primary launch class extending the Application class
public class App extends Application {

    /**
     *
     * @param stage
     */
    @Override
    public void start(Stage stage) {
        //load the view.fxml file, add it to the scene and show it
        try {
            Parent parent = FXMLLoader.load(getClass().getResource("/fxml/view.fxml"));
            //create a scene
            Scene scene = new Scene(parent);
            //set scene to a stage
            stage.setScene(scene);
            //show the stage
            stage.show();
        }//end try
        catch (IOException e) {
            e.printStackTrace();
        }//end catch
    }//end start method

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

}//end App class

The main file extends the Application class and overrides its abstract method start(). In the start() method, we load the view.fxml file, create a scene, set this scene to a stage, and display that stage.

OUTPUT (prints the word CLICK on IDE’s console whenever we click on the Button):

Solution to JavaFX fxml Load Exception - Output

Check the following screenshot to place each file at the correct location:

Solution to JavaFX fxml Load Exception - Files Directory

We will learn how to fix the JavaFX exception in the application start method.

Before going into the concept, a quick look at JavaFX.
JavaFX is a software platform used for creating and delivering desktop applications. JavaFX is a set of graphics and media packages that enables developers to design, create, test, debug, and deploy rich client applications that operate consistently across diverse platforms.

Exception in the Application Start method is the runtime error that occurs when the application is running and when compilation gets done. This state occurs when the application is inefficient in loading runtime variables or files.

JavaFX code

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

public class Main extends Application { 
            @Override
               public void start(Stage stage) throws Exception { 
                  Parent root = 
                  FXMLLoader.load(getClass().getResource("SampleXML.fxml")); 
                  Scene scene = new Scene(root); 
                  stage.setScene(scene); 
                  stage.setTitle("hello"); 
                  stage.show(); 
             } 
public static void main(String[] args) { 
                  launch(args); 
             } 
        }

Explanation

In the above block of code, the main method is written inside the class ‘Main’ which extends an abstract Application class. Inside the main method, we have written launch(args);, this statement uses the launch() method which is a static method located in the Application class. This method will detect from which class it is called, so you don’t have to tell what class to launch.

public void start(Stage stage) throws Exception

The above statement is the main entry point for all JavaFX applications. This method is called on the JavaFX application thread. Inside this method, we have given some data “Stage” is the keyword and “stage” is the primary stage. This method throws an Exception.

stage.setScene(scene); 
stage.setTitle("hello"); 
stage.show(); 

setScene(scene); is used because a JavaFX scene can be attached to only a single stage at a time, and the stage can also only display one scene at a time. setTitle is used to set the title for the stage, in the above case the title set is hello. show() is used to display the stage.

The output for the above code is.

Exception in Application start method 
java.lang.reflect.InvocationTargetException 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source) 
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source) 
Caused by: java.lang.RuntimeException: Exception in Application start method 
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source) 
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(Unknown Source) at com.sun.javafx.application.LauncherImpl$$Lambda$48/1732398722.run(Unknown Source) 
at java.lang.Thread.run(Unknown Source) 
Caused by: java.lang.NullPointerException: Location is required. 
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) 
at javafx.fxml.FXMLLoader.load(Unknown Source) at application.Main.start(Main.java:14) 
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(Unknown Source) at com.sun.javafx.application.LauncherImpl$$Lambda$51/1778973910.run(Unknown Source) 
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(Unknown Source) 
at com.sun.javafx.application.PlatformImpl$$Lambda$44/1051754451.run(Unknown Source) 
at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Source) 
at com.sun.javafx.application.PlatformImpl$$Lambda$47/813155481.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown Source) 
at com.sun.javafx.application.PlatformImpl$$Lambda$46/1775282465.run(Unknown Source) 
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source) 
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source) 
at com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(Unknown Source) ... 1 more 
Exception running application application.Main

Explanation

In the above-shown output, the error occurred at the parameter position at FXML Loader which loads the XML object. We see a NullPointerException has occurred when we are trying to open a file, the reason for this exception could be a wrong path. When using Class.getResource() method we must provide a local path from the location of the class which is called the method.

Solutions

  1. Provide a correct path where the file is present.
  2. You can fix the exception by updating your code or adding the required JavaFX modules. As a result, your code will work as expected.
  3. The exception in application start method java.lang.reflect.InvocationTargetException is an error code that occurs when you are using JavaFX. There are myriad situations that cause this error. Keep on reading, as we’ll give you detailed explanations of these causes and their fix.
  4. When you load your FXML file with FXMLLoader, observe if there is a forward slash in the pathname of the FXML file. If you are getting an exception, remove this forward slash. Afterward, your code should work. For example, the following is a code we showed you earlier:
FXMLLoader loader = new FXMLLoader(Main.class.getResource(“/File.fxml”));

From the code, we have the forward slash before File.fxml but in the code below, we’ve eliminated the forward slash. So, your code should work.

// Take out the “/” before the FXML file

FXMLLoader loader = new FXMLLoader(Main.class.getResource(“File.fxml”));

There are cases where the absence of the forward slash caused an exception. So, if you are in such a situation, add the forward slash to prevent the exception.

  1. In IntelliJ IDEA, you’ll need to add the JavaFX modules as a VM option based on your Operating System. We say “JavaFX modules” because JavaFX is a collection of modules. We base this solution on the “Getting Started” tutorial on OpenJFX. Earlier, we mentioned that if you compile your code without the JavaFX modules, you’ll get an error.
    a) To add the VM options, go to the following location in IntelliJ IDEA:
    Run → Edit Configurations
    b) At the above location, if you are on Windows, add the VM options using the following:
    –module-path “pathtojavafx-sdk-17.0.1lib” –add-modules javafx.controls,javafx.fxml
    c) If you are on Linux or Mac, use the following:
    –module-path /path/to/javafx-sdk-17.0.1/lib –add-modules javafx.controls,javafx.fxml
  2. A starting forward slash in the path name of an FXML file can cause an exception.
    a) Not setting the root before loading the XML file leads to an exception.
    b) To prevent an exception when working with JavaFX in IntelliJ, use JavaFX modules.
    c) You can add JavaFX modules as VM options in IntelliJ IDEA.
    d) You can prevent the failure from happening by setting the root on FXMLLoader before you load your FXML file.
  3. Add a SonarLint plugin to the Integrated Development Environment that helps in evaluating or handling the exceptions at the write time.

Conclusion

In the above article, we have learned about what is JavaFX, what is Exception in the application start method, the Cause Exception in the application start method, sample code to understand this exception, and the solution to this exception.

I am using Intellij (JavaFX with Maven module), after adding the javafx plugins I get the following error:
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:567)
	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:567)
	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:835)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x36cbb069) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module @0x36cbb069
	at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
	at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
	at app.Main.start(Main.java:24)
	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:389)
	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
Exception running application app.Main

it is happening on:
Parent root = FXMLLoader.load(getClass().getResource("/sample.fxml")); // The sample.fxml is in the resources folder
Here is my maven pom file:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>Pere</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.3</version>
                <configuration>
                    <mainClass>org.openjfx.App</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>12.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>12.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>12.0.2</version>
        </dependency>
    </dependencies>



</project>

Я не могу понять для жизни меня проблема с этим кодом. Я провел здесь исследование многих подобных вопросов, обращая внимание на то, были ли каталоги правильными, возможные неправильные вызовы функций и т. д.

Я надеюсь, что кто-то может мне помочь. Все находится в файле с именем login в приложении под названием loginapp.

Вот Логин.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package login;

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


public class Login extends Application   {

    @Override
    public void start(Stage stage) throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("Login.fxml"));
        Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("Login.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("Fracken");
        stage.show();
    }
}

Вот Логин.fxml

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

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" prefHeight="317.0" prefWidth="326.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="login.Login">
   <children>
      <TextField fx:id="txtUsername" layoutX="110.0" layoutY="45.0" promptText="Username" />
      <PasswordField fx:id="txtPassword" layoutX="110.0" layoutY="115.0" promptText="Password" />
      <Button fx:id="btnLogin" layoutX="110.0" layoutY="184.0" mnemonicParsing="false" onAction="btnLoginAction" text="Login" />
      <Button fx:id="btnReset" layoutX="232.0" layoutY="184.0" mnemonicParsing="false" onAction="btnResetAction" text="Reset" />
      <Label fx:id="lblMessage" layoutX="110.0" layoutY="236.0" prefHeight="31.0" prefWidth="187.0" />
   </children>
</AnchorPane>

Я уверен, что проблема в

Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("Login.fxml"));

Я получаю эту ошибку.

Executing C:\Users\David\Desktop\Java Project\loginapp\dist\run122343396\loginapp.jar using platform C:\Program Files\Java\jdk1.8.0_111\jre/bin/java
Exception in Application start method
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: Location is required.
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
    at login.Login.start(Login.java:23)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    ... 1 more
Java Result: 1

Пожалуйста, помогите мне, я смотрел на другие подобные проблемы здесь, но решения не работали.

Понравилась статья? Поделить с друзьями:
  • Fubag ds 5500 a es ошибка l 6
  • G403 тиндер ошибка
  • Fx1006 05 ошибка
  • Fuel ошибка при запуске
  • Ftyn50lv1b коды ошибок