FXML ClassNotFoundException
<h1>Error</h1>

<pre><code>C:\Users\rbenedict\Documents\Java Modules&gt;java -cp .;fxmltut fxmltut.FXMLEx
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(Unk
nown Source)
        at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Sou
rce)
        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 So
urce)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(
Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: javafx.fxml.LoadException:
/C:/Users/rbenedict/Documents/Java%20Modules/fxmltut/FXMLDoc.fxml

        at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
        at javafx.fxml.FXMLLoader.importClass(Unknown Source)
        at javafx.fxml.FXMLLoader.processImport(Unknown Source)
        at javafx.fxml.FXMLLoader.processProcessingInstruction(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.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 fxmltut.FXMLEx.start(FXMLEx.java:17)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162
(Unknown Source)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown
 Source)
        at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Sourc
e)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown S
ource)
        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$148(Unknown Source)
        ... 1 more
Caused by: java.lang.ClassNotFoundException
        at javafx.fxml.FXMLLoader.loadType(Unknown Source)
        ... 21 more
Exception running application fxmltut.FXMLEx
</code></pre>

<p>I tried with and without package <code>fxmltut</code>. Without I get the same exception and did some checking online.  Apparently, javafx parses the import statement by looking for the <code>.</code> token and taking the identifier after.  So I made it part of a package and I am still getting the same error.</p>

<h1>FXMLEx.java</h1>

<pre><code>package fxmltut;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;

import javafx.scene.Parent;
import java.lang.Class;

import javafx.fxml.FXMLLoader;

public class FXMLEx extends Application {

    @Override
    public void start(Stage stage) throws Exception {

        Parent root = FXMLLoader.load(getClass().getResource("FXMLDoc.fxml"));
        Scene scene = new Scene(root, 300,275);

        stage.setTitle("FXML Welcome");
        stage.setScene(scene);
        stage.show();

    }

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

}
</code></pre>

<h1>FXMLCont.java</h1>

<pre><code>package fxmltut;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.text.Text;

public class FXMLCont {
    @FXML private Text actTarg;
    @FXML protected void handleSubmitButtonAction(ActionEvent event) {
        actTarg.setText("Sign in button pressed");
    }
}
</code></pre>

<h1>FXMLDoc.fxml</h1>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;?import fxmltut.*?&gt;
&lt;?import java.net.*?&gt;
&lt;?import java.geometry.*?&gt;
&lt;?import java.scene.control*?&gt;
&lt;?import java.scene.layout.*?&gt;
&lt;?import java.scene.text.*?&gt;

&lt;GridPane fx:controller="fxmltut.FXMLCont"

    xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10"&gt;
    &lt;padding&gt;&lt;Insets top="25" right="25" bottom="25" left="25"/&gt;&lt;/padding&gt;

&lt;/GridPane&gt;

&lt;Text text="Welcome"
    GridePane.columnIndex="0" GridPane.rowIndex="0"
    GridPane.columnSpan="2"/&gt;

&lt;Label text="User Name:"
    GridPane.columnIndex="0" GridPane.rowIndex="1"/&gt;
&lt;TextField
    GridPane.columnIndex="1" GridPane.rowIndex="1"/&gt;

&lt;Label text="Password:"
    GridPane.columnIndex="0" GridPane.rowIndex="2"/&gt;

&lt;PasswordField fx:id="pw" GridPane.columnIndex="1" GridPane.rowIndex="2"/&gt;

&lt;HBox spacing="10" alignment = "bottom_right"
    GridPane.columnIndex="1" GridPane.rowIndex="4"&gt;

    &lt;Button text="Sign in"
    onAction="#handleSubmitButtonAction"/&gt;

&lt;/HBox&gt;

&lt;Text fx:id="actTarg"
    GridPane.columnIndex="0" GridPane.columnSpan="2"
    GridPane.halignment="RIGHT" GridPane.rowIndex="6" /&gt;
</code></pre>