-3

I am using Netbeans IDE and created that file using Scene Builder 2.0. I created all the user interface using Scene Builder.

When I try to run the application this exception comes. I created JavaFX FXML application in Netbeans IDE and opened the fxml in scene builder and edited and after completion ran it in Netbeans but failed to get the desired screen.

ERROR:

Executing C:\J_Progs\Login\dist\run1115386562\Login.jar using platform C:\Program Files\Java\jdk1.8.0_66\jre/bin/java
Exception in Application start method
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:497)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    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:497)
    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: javafx.fxml.LoadException: 
file:/C:/J_Progs/Login/dist/run1115386562/Login.jar!/login/Login.fxml:35

    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.loadImpl(FXMLLoader.java:3214)
    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
Caused by: java.lang.IllegalArgumentException: Can not set javafx.scene.control.Label field login.LoginController.txtUser to javafx.scene.control.TextField
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
    at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
    at java.lang.reflect.Field.set(Field.java:764)
    at javafx.fxml.FXMLLoader.injectFields(FXMLLoader.java:1163)
    at javafx.fxml.FXMLLoader.access$1600(FXMLLoader.java:103)
    at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:857)
    at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:751)
    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
    ... 17 more
Exception running application login.Login

Login.fxml:

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

<?import javafx.scene.paint.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" prefHeight="600.0" prefWidth="650.0" style="-fx-background-color: #DCDCDC;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="login.LoginController">
   <children>
      <Label fx:id="lblMsg" layoutX="47.0" layoutY="39.0" text="WELCOME" textAlignment="CENTER">
         <font>
            <Font name="System Bold" size="40.0" />
         </font>
      </Label>
      <Label layoutX="271.0" layoutY="229.0" text="SIGN IN">
         <font>
            <Font name="System Bold" size="24.0" />
         </font>
      </Label>
      <Label layoutX="130.0" layoutY="300.0" text="USERNAME">
         <font>
            <Font size="15.0" />
         </font>
      </Label>
      <Label layoutX="129.0" layoutY="379.0" text="PASSWORD">
         <font>
            <Font size="15.0" />
         </font>
      </Label>
      <TextField fx:id="txtUser" layoutX="265.0" layoutY="298.0" prefHeight="25.0" prefWidth="235.0" promptText="Enter Username" />
      <Button layoutX="289.0" layoutY="481.0" mnemonicParsing="false" onAction="#loginAction" opacity="0.84" style="-fx-background-color: #1e90ff;" text="SIGN IN" textFill="WHITE">
         <font>
            <Font size="15.0" />
         </font>
      </Button>
      <PasswordField fx:id="txtPass" layoutX="265.0" layoutY="377.0" prefHeight="25.0" prefWidth="235.0" promptText="Enter Password" />
      <Rectangle arcHeight="18.0" arcWidth="18.0" fill="SILVER" height="174.0" layoutX="83.0" layoutY="264.0" opacity="0.41" stroke="BLACK" strokeType="INSIDE" width="506.0" />
      <Rectangle arcHeight="12.0" arcWidth="12.0" fill="DODGERBLUE" height="35.0" layoutX="86.0" layoutY="229.0" opacity="0.67" stroke="BLACK" strokeType="INSIDE" width="500.0" />
   </children>
</AnchorPane>

LoginController.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 java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;



public class LoginController implements Initializable {

    @FXML
    private Label lblMsg;
    @FXML
    private Label txtUser;
    @FXML
    private Label txtPass;


    @FXML
    private void loginAction(ActionEvent event) {
        if(txtUser.getText().equals("rs954") && txtPass.getText().equals("admin"))
        {
            lblMsg.setText("WELCOME");
        }    
        else
        {
            lblMsg.setText("WRONG CREDENTIALS");
        }    
        }    

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    } 
}

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 java.io.IOException;
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 primaryStage) throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("Login.fxml"));

        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

}

NEW ERROR:

Executing C:\J_Progs\Login\dist\run384200010\Login.jar using platform C:\Program Files\Java\jdk1.8.0_66\jre/bin/java
Exception in Application start method
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:497)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    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:497)
    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: javafx.fxml.LoadException: 
file:/C:/J_Progs/Login/dist/run384200010/Login.jar!/login/Login.fxml

    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.loadImpl(FXMLLoader.java:3214)
    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
Caused by: java.lang.UnsupportedOperationException: Not supported yet.
    at login.LoginController.initialize(LoginController.java:44)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
    ... 17 more

Exception running application login.Login

NEW EDIT IN LoginController.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 java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;


public class LoginController implements Initializable {

    @FXML
    private Label lblMsg = new Label();
    @FXML
    private TextField txtUser = new TextField ();
    @FXML
    private TextField txtPass = new TextField ();


    @FXML
    private void loginAction(ActionEvent event) {
        if(txtUser.getText().equals("rs95    4") && txtPass.getText().equals("admin"))
        {
            lblMsg.setText("WELCOME");
        }    
        else
        {
            lblMsg.setText("WRONG CREDENTIALS");
        }    
    }    

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    } 
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Rocker Rocky
  • 97
  • 4
  • 16
  • Here is your problem `java.lang.IllegalArgumentException: Can not set javafx.scene.control.Label field login.LoginController.txtUser to javafx.scene.control.TextField` – F. Lumnitz Jan 29 '16 at 07:26
  • 1
    You seriously wonder why an exception is thrown, if you write `throw new UnsupportedOperationException("Not supported yet.");` (A cause that is very easily identifiable in the stack trace btw: `Caused by: java.lang.UnsupportedOperationException: Not supported yet. at login.LoginController.initialize(LoginController.java:44)`)??? – fabian Jan 29 '16 at 11:43

1 Answers1

2

txuser in your fxml file is a textfield: <TextField fx:id="txtUser" and in your application a Label private Label txtUser. You should use the same widget in both.

Jens
  • 67,715
  • 15
  • 98
  • 113
  • so what should i add and remove in my code. Help would be really appreciated – Rocker Rocky Jan 29 '16 at 07:46
  • @RockerRocky Look here: https://docs.oracle.com/javafx/2/ui_controls/text-field.htm – Jens Jan 29 '16 at 07:47
  • I added this-: private Label lblMsg = new Label(); private TextField txtUser = new TextField (); private TextField txtPass = new TextField (); Still getting the same error – Rocker Rocky Jan 29 '16 at 07:53
  • @RockerRocky same error for the same field? – Jens Jan 29 '16 at 07:55
  • can you tell what i have to write instead of the above label and textfield code i wrote. – Rocker Rocky Jan 29 '16 at 07:57
  • Caused by: java.lang.UnsupportedOperationException: Not supported yet. at login.LoginController.initialize(LoginController.java:44) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548) ... 17 more This came instead of Illegal Argument Exception @Jens – Rocker Rocky Jan 29 '16 at 07:58
  • Add the compleate stacktrace to your question – Jens Jan 29 '16 at 08:00
  • @RockerRocky That is not the correct way to do it. You need to replace `@FXML private Label txtUser;` with `@FXML private TextField txtUser;` and `@FXML private Label txtPass;` with `@FXML private PasswordField txtPass;` – ItachiUchiha Jan 29 '16 at 08:05