0

当我尝试从 JfxpasswordField 获取密码值时,出现以下异常。在进行研究之后,我遇到了一个建议我使用场景 bulder 8.5 的解决方案,但不幸的是,这并没有解决我的问题。请协助解决此问题

下面是产生错误的代码标题。错误发生在这一行

PasswordValue = password.getText();

这是代码片段

package com.kayseensystems.posmaxpro;

import com.jfoenix.controls.JFXTextField;
import com.kayseensystems.posmaxpro.Datalayer.User;
import com.kayseensystems.posmaxpro.Services.LonginService;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Pos;
import javafx.util.Duration;
import org.controlsfx.control.Notifications;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.jfoenix.controls.JFXPasswordField;
@Controller
public class FXMLController implements Initializable {

    @Autowired
    private LonginService longinService;
    @FXML
    private JFXPasswordField password;

    @FXML
    private JFXTextField username;

    @FXML
    private void loginButton(ActionEvent event) throws Exception {
       String usernamevalue=username.getText();
       String PasswordValue;
        PasswordValue = password.getText();
        System.out.println("Username="+usernamevalue+" "+PasswordValue);
        try {
        User user=longinService.SystemLogin(usernamevalue,PasswordValue);
        if(user==null){
            Notifications notify=Notifications.create()
                    .title("Login").text("The provided user does Not Exist.Kindly consult Management")
                    .graphic(null).hideAfter(Duration.seconds(5))
                    .position(Pos.TOP_LEFT);
            notify.showError();
        }else{
            Notifications notify=Notifications.create()
                    .title("Login").text("Logged in Successful")
                    .graphic(null).hideAfter(Duration.seconds(5))
                    .position(Pos.TOP_LEFT);
            notify.showInformation();
        }
        } catch (Exception e) {
          e.getCause().printStackTrace();
        }

    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
    }
}

错误堆栈跟踪

 Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
     at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
     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:394)
     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$353(GlassViewEventHandler.java:432)
     at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
     at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
     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$147(WinApplication.java:177)
     at java.lang.Thread.run(Thread.java:748)
    Caused by: 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.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
     at sun.reflect.GeneratedMethodAccessor41.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.lang.reflect.Method.invoke(Method.java:498)
     at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
     at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
     ... 48 more
    Caused by: java.lang.NullPointerException
     at com.kayseensystems.posmaxpro.FXMLController.loginButton(FXMLController.java:50)
     ... 58 more
    2018-07-18 01:40:51.735  WARN 6444 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=3m21s762ms818µs939ns).
    2018-07-18 02:06:33.846  INFO 6444 --- [lication Thread] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase 2147483647
    2018-07-18 02:06:33.851  INFO 6444 --- [lication Thread] org.quartz.core.QuartzScheduler          : Scheduler quartzScheduler_$_NON_CLUSTERED paused.
    2018-07-18 07:48:57.461  WARN 6444 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=5h12m35s558ms294µs497ns).

这是fxml

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

<?import com.jfoenix.controls.JFXPasswordField?>
<?import com.jfoenix.controls.JFXTextField?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Hyperlink?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.effect.Lighting?>
<?import javafx.scene.effect.Shadow?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<AnchorPane id="AnchorPane" fx:id="FXMLController" prefHeight="594.0" prefWidth="779.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.kayseensystems.posmaxpro.FXMLController">
    <children>
        <VBox alignment="CENTER" layoutX="-11.0" layoutY="-6.0" prefHeight="594.0" prefWidth="349.0" style="-fx-background-color: #6a5acd;" AnchorPane.bottomAnchor="6.0" AnchorPane.topAnchor="-6.0">
            <children>
                <ImageView fx:id="image1" cache="true" fitHeight="73.0" fitWidth="155.0" focusTraversable="true" pickOnBounds="true" VBox.vgrow="ALWAYS">
                    <image>
                        <Image url="@../../../icons/Capture.JPG" />
                    </image>

                    <VBox.margin>
                        <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
                    </VBox.margin>
                </ImageView>
                <Label prefHeight="18.0" prefWidth="94.0" text="Welcome To" textAlignment="RIGHT" textFill="WHITE" VBox.vgrow="ALWAYS">
                    <font>
                        <Font name="Eras Bold ITC" size="14.0" />
                    </font>
                    <effect>
                        <Lighting>
                            <bumpInput>
                                <Shadow />
                            </bumpInput>

                        </Lighting>
                    </effect>
                </Label>
                <Label text="Pos Max Pro" textFill="WHITE" VBox.vgrow="ALWAYS">
                    <font>
                        <Font name="Impact" size="24.0" />
                    </font>
                </Label>
            </children>
        </VBox>
        <Pane layoutX="393.0" prefHeight="594.0" prefWidth="434.0" style="-fx-background-color: #FFFF;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="345.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
            <children>
                <ImageView fx:id="image2" fitHeight="150.0" fitWidth="201.0" layoutX="7.0" layoutY="6.0" pickOnBounds="true" preserveRatio="true">
                    <image>
                        <Image url="@../../../icons/innerview.JPG" />
                    </image>
                </ImageView>
                <Label layoutX="32.0" layoutY="144.0" prefHeight="18.0" prefWidth="138.0" text="Welcome Back">
                    <font>
                        <Font name="Ebrima Bold" size="18.0" />
                    </font>
                </Label>
                <Label layoutX="36.0" layoutY="167.0" prefHeight="18.0" prefWidth="124.0" text="sign in to continue" />
                <Hyperlink fx:id="signup" layoutX="171.0" layoutY="424.0" prefHeight="29.0" prefWidth="110.0" text="Sign up here" textFill="SLATEBLUE">
                    <font>
                        <Font name="Ebrima Bold" size="16.0" />
                    </font>
                </Hyperlink>
                <Hyperlink fx:id="passwordchange" layoutX="31.0" layoutY="424.0" prefHeight="26.0" prefWidth="117.0" text="forgot password" textFill="ROYALBLUE">
                    <font>
                        <Font name="System Bold" size="12.0" />
                    </font>
                </Hyperlink>
                <Button fx:id="Login" layoutX="35.0" layoutY="493.0" mnemonicParsing="false" onAction="#loginButton" prefHeight="35.0" prefWidth="110.0" style="-fx-background-color: #00CED1; -fx-background-radius: 10; -fx-border-radius: 10;" text="Button" textFill="WHITE">
                    <font>
                        <Font name="Ebrima Bold" size="22.0" />
                    </font>
                </Button>
                <JFXTextField fx:id="username" focusColor="#6747cd" labelFloat="true" layoutX="34.0" layoutY="276.0" prefHeight="35.0" prefWidth="241.0" promptText="username" unFocusColor="#6747cd" />
            <JFXPasswordField id=" password" fx:id="password" labelFloat="true" layoutX="31.0" layoutY="364.0" prefHeight="35.0" prefWidth="241.0" promptText="Password" />
            </children>
        </Pane>
    </children>
</AnchorPane>

在此处输入图像描述

在此处输入图像描述

4

0 回答 0