0

The error is being produced at showAdminLoginScene() method, However if I modify this method and I put another fxml file from the same package to load, it loads just fine : here's my Main :

package application;

import java.io.IOException;

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

public class Main extends Application {
  private Stage primaryStage;
  private static BorderPane mainLayout;
  @Override
public void start(Stage primaryStage) throws IOException {
    this.primaryStage= primaryStage;
    this.primaryStage.setTitle("LAU LABS");
    showMainView();
}
private void showMainView() throws IOException{
    FXMLLoader loader=new FXMLLoader();
    loader.setLocation(Main.class.getResource("MainView.fxml"));

    mainLayout=loader.load();


    Scene scene=new Scene(mainLayout);
    primaryStage.setScene(scene);
    primaryStage.show();
}

public static void showAdminLoginScene() {
    FXMLLoader loader=new FXMLLoader();
    loader.setLocation(Main.class.getResource("AdminLogin.fxml"));
    BorderPane adminLogin;
    try {
        adminLogin = loader.load();
        mainLayout.setCenter(adminLogin);
        } catch (IOException e) {
        e.printStackTrace();
    }

}
public static void showAdminLoggedIn() {
    FXMLLoader loader=new FXMLLoader();
    loader.setLocation(Main.class.getResource("AdminLoggedIn.fxml"));
    AnchorPane adminLoggedIn;
    try {
        adminLoggedIn = loader.load();
        mainLayout.setCenter(adminLoggedIn);
    } catch (IOException e) {
        System.out.println("the error is in Main, ShowAdminLoggedIn");
    }

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

And here's my controller class :

package application;

import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.io.IOException;

import javafx.fxml.FXML;


public class AdminLoginController {
   @FXML private TextField txtUsername;
   @FXML private TextField txtPassword;
   @FXML private Label lblStatus;
   private Main main;


public void Login(ActionEvent event) {
   if(txtUsername.getText().equals("user")&& 
         txtPassword.getText().equals("pass")){
    main.showAdminLoggedIn();
}
else{
    lblStatus.setText("Login Failed!");
}
}
}

Here's my fxml :

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

<?import com.gluonhq.charm.glisten.control.TextField?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.text.Text?>


<BorderPane xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.AdminLoginController">
   <center>
      <AnchorPane prefHeight="300.0" prefWidth="300.0">
         <children>
            <TextField fx:id="txtUsername" layoutX="56.0" layoutY="79.0" prefHeight="26.0" prefWidth="189.0" />
            <PasswordField fx:id="txtPassword" layoutX="56.0" layoutY="150.0" prefHeight="26.0" prefWidth="189.0" />
            <Button layoutX="56.0" layoutY="227.0" mnemonicParsing="false" onAction="#Login" prefHeight="32.0" prefWidth="189.0" style="-fx-background-color: #004c3c;" text="Login" />
            <Text fill="#004c3c" layoutX="56.0" layoutY="75.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Username" wrappingWidth="60.98307228088379" />
            <Text fill="#004c3c" layoutX="56.0" layoutY="146.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Password" />
            <Button layoutX="1.0" minWidth="52.0" mnemonicParsing="false" prefHeight="39.0" prefWidth="52.0" style="-fx-background-color: Transparent;" />
            <ImageView fitHeight="35.0" fitWidth="200.0" layoutX="10.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true">
               <image>
                  <Image url="@BackButton.png" />
               </image>
            </ImageView>
            <Label fx:id="lblStatus" layoutX="56.0" layoutY="202.0" prefHeight="16.0" prefWidth="189.0" style="-fx-text-fill: Red;" text="Status: " />
         </children>
      </AnchorPane>
   </center>
</BorderPane>

They're all in the same package named "application" (the fxml, controller and main)

That's the error :

javafx.fxml.LoadException: 
/C:/Users/Owner/Documents/UNI/programming/workspace/Lau/bin/application/AdminLogin.fxml

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
    at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2848)
    at javafx.fxml.FXMLLoader.processImport(FXMLLoader.java:2692)
    at javafx.fxml.FXMLLoader.processProcessingInstruction(FXMLLoader.java:2661)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2517)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
    at application.Main.showAdminLoginScene(Main.java:39)
    at application.MainViewController.goAdminLogin(MainViewController.java:8)
    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.reflect.misc.Trampoline.invoke(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Node.fireEvent(Node.java:8413)
    at javafx.scene.control.Button.fire(Button.java:185)
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:417)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
    at com.sun.glass.ui.View.notifyMouse(View.java:937)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.gluonhq.charm.glisten.control.TextField
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at javafx.fxml.FXMLLoader.loadTypeForPackage(FXMLLoader.java:2916)
    at javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:2905)
    at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2846)
    ... 65 more
3
  • please post the exception trace Commented Dec 6, 2017 at 12:55
  • @DVarga Done, please help ! Commented Dec 6, 2017 at 12:59
  • Could you add you pom.xml or build.gradle? are you using scene builder with Gluon's Charm library? Commented Dec 6, 2017 at 13:23

2 Answers 2

4

You are using an incorrect TextField (I guess it is not intentional) in your FXML:

<?import com.gluonhq.charm.glisten.control.TextField?>

which is causing:

Caused by: java.lang.ClassNotFoundException: com.gluonhq.charm.glisten.control.TextField

You can change the import as ...

<?import javafx.scene.control.TextField?>

to use the built-in TextField.

Sign up to request clarification or add additional context in comments.

7 Comments

Still not working :/ javafx.fxml.LoadException: /C:/Users/Owner/Documents/UNI/programming/workspace/Lau/bin/application/AdminLogin.fxml:18 at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) at application.Main.showAdminLoginScene(Main.java:39) at application.MainViewController.goAdminLogin(MainViewController.java:8)...
And that's line 18 <TextField fx:id="txtUsername" layoutX="56.0" layoutY="79.0" prefHeight="26.0" prefWidth="189.0" />
If you got the same exception -> clean and build.
Im not getting the same exception, now it's pointing to line 18 which contains the TextField attribute, however I rebuilt it and it's still showing this error.
@yaranefaa your "controller" class uses import java.awt.TextField; you need to fix that also to be javafx.scene.control.TextField. Your main class class needs to fix the AWT imports to JAVAFX. Be careful with imports as sometimes IDEs will import incorrectly if you use their "Auto-import" feature.
|
1

You're missing Gluon's Charm library, you should add it in your build automation tool:

For maven project:

<dependencies>
...
<dependency>
    <groupId>com.gluonhq</groupId>
    <artifactId>charm-glisten</artifactId>
    <version>4.4.1</version> // Change version as needed 
</dependency>
...
</dependencies>
<repositories>
       <repository>
         <id>nexus-com-gluonhq</id>
         <name>Nexus repo</name>
         <url>http://nexus.gluonhq.com/nexus/content/repositories/releases</url>
       </repository>
</repositories>

for Gradle:

.

..
repositories {
    ....
    maven {
        url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
   ...
}

dependencies {
    compile 'com.gluonhq:charm-glisten:4.4.1'
    ...
}

By the way, in your controller class use javafx.scene.control instead of java.awt as you're using JavaFX project

1 Comment

Oops! I didn't refresh to see @DVarga answer, maybe my answer will help someone with the same issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.