当我在登录屏幕中按下一步按钮时,出现以下错误:
线程“ JavaFX Application Thread”中的异常null java.lang.RuntimeException: java.lang.reflect.InvocationTargetException在 javafx.fxml.FXMLLoader $ MethodHandler.invoke(FXMLLoader.java:1774)在 javafx.fxml.FXMLLoader $ ControllerMethodEventHandler.handle(FXMLLoader.java:1657) 在 com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86) 在 com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) 在 com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) 在 com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 在com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) 在com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)处 javafx.event.Event.fireEvent(Event.java:198)在 javafx.scene.Node.fireEvent(Node.java:8411)在 javafx.scene.control.Button.fire(Button.java:185)在 com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182) 在 com.sun.javafx.scene.control.skin.BehaviorSkinBase $ 1.handle(BehaviorSkinBase.java:96) 在 com.sun.javafx.scene.control.skin.BehaviorSkinBase $ 1.handle(BehaviorSkinBase.java:89) 在 com.sun.javafx.event.CompositeEventHandler $ NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218) 在 com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80) 在 com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) 在 com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) 在 com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 在 com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 在 com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 在com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) 在com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)处 javafx.event.Event.fireEvent(Event.java:198)在 javafx.scene.Scene $ MouseHandler.process(Scene.java:3757)在 javafx.scene.Scene $ MouseHandler.access $ 1500(Scene.java:3485)在 javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)在 javafx.scene.Scene $ ScenePeerListener.mouseEvent(Scene.java:2494)在 com.sun.javafx.tk.quantum.GlassViewEventHandler $ MouseEventNotification.run(GlassViewEventHandler.java:394) 在 com.sun.javafx.tk.quantum.GlassViewEventHandler $ MouseEventNotification.run(GlassViewEventHandler.java:295) 在java.security.AccessController.doPrivileged(本机方法)在 com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda $ handleMouseEvent $ 353(GlassViewEventHandler.java:432) 在 com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389) 在 com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431) 在com.sun.glass.ui.View.handleMouseEvent(View.java:555)处 com.sun.glass.ui.View.notifyMouse(View.java:937)在 com.sun.glass.ui.win.WinApplication._runLoop(本机方法)位于 com.sun.glass.ui.win.WinApplication.lambda $ null $ 147(WinApplication.java:177) 在java.lang.Thread.run(未知源)造成原因: java.lang.reflect.InvocationTargetException在 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)位于 sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)位于 sun.reflect.DelegatingMethodAccessorImpl.invoke(未知源)位于 java.lang.reflect.Method.invoke(来源未知) sun.reflect.misc.Trampoline.invoke(未知来源)位于 sun.reflect.GeneratedMethodAccessor1.invoke(未知源)位于 sun.reflect.DelegatingMethodAccessorImpl.invoke(未知源)位于 java.lang.reflect.Method.invoke(来源未知) sun.reflect.misc.MethodUtil.invoke(未知来源)位于 javafx.fxml.FXMLLoader $ MethodHandler.invoke(FXMLLoader.java:1771)... 48个以上的原因:java.lang.NumberFormatException:对于输入字符串: java.lang.NumberFormatException.forInputString上的“”(未知源) 在java.lang.Integer.parseInt(未知源)在 java.lang.Integer.valueOf(来源未知) sample.controller.LoginController.login(LoginController.java:29)... 另外58个
我的登录页面:
import com.jfoenix.controls.JFXPasswordField;
import com.jfoenix.controls.JFXTextField;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import sample.entity.Doctor;
import sample.entity.Patient;
import sample.db.SqlControl;
import java.io.IOException;
public class LoginController {
private MainController mainController;
public void setMainController(MainController mainController) {
this.mainController = mainController;
}
@FXML
JFXTextField loginField;
@FXML
JFXPasswordField passwordField;
@FXML
Text error;
@FXML
public void login() {
String query = SqlControl.Login(loginField.getText(), passwordField.getText());
if (Integer.valueOf(query) == 0) {
error.setVisible(true);
} else {
if (Integer.valueOf(SqlControl.isAccountEnabled(loginField.getText())) != 0)
LoadCabinet(SqlControl.loginRole(loginField.getText(), passwordField.getText()));
else
error.setVisible(true);
}
}
@FXML
public void backToMenu() {
mainController.loadMenuScreen();
}
private void LoadCabinet(String role) {
FXMLLoader loader;
Pane pane;
if (role.equals("admin")) {
Doctor doctor = new SqlControl().getDoctorByLogin(loginField.getText());
loader = new FXMLLoader(this.getClass().getResource("../resources/Doctor.fxml"));
pane = null;
try {
pane = loader.load();
} catch (IOException e) {
e.printStackTrace();
}
DoctorController doctorController = loader.getController();
doctorController.setDoctor(doctor);
doctorController.Refresh();
doctorController.setMainController(mainController);
mainController.setScreen(pane);
} else {
if (role.equals("user")) {
Patient patient = new SqlControl().getPatientByLogin(loginField.getText());
loader = new FXMLLoader(this.getClass().getResource("../resources/Patient.fxml"));
pane = null;
try {
pane = loader.load();
} catch (IOException e) {
e.printStackTrace();
}
PatientController patientController = loader.getController();
patientController.setMainController(mainController);
patientController.setPatient(patient);
patientController.Refresh();
mainController.setScreen(pane);
}
}
}
我的登录fxml页面:
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXTextField?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<?import com.jfoenix.controls.JFXPasswordField?>
<Pane id="pane-doctor" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="700.0" stylesheets="@css/style.css" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.controller.LoginController">
<children>
<JFXTextField fx:id="loginField" layoutX="273.0" layoutY="141.0" />
<JFXPasswordField fx:id="passwordField" layoutX="273.0" layoutY="224.0" />
<Text layoutX="50.0" layoutY="133.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Login" textAlignment="CENTER" wrappingWidth="600.0">
<font>
<Font name="Ubuntu Light" size="25.0" />
</font>
</Text>
<Text layoutX="50.0" layoutY="218.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Password" textAlignment="CENTER" wrappingWidth="600.0">
<font>
<Font name="Ubuntu Light" size="25.0" />
</font>
</Text>
<JFXButton id="menu-button" fx:id="logAsADoctor" layoutX="269.0" layoutY="276.0" mnemonicParsing="false" onAction="#login" prefHeight="53.0" prefWidth="165.0" stylesheets="@css/style.css" text="Next">
<font>
<Font name="Ubuntu Light" size="13.0" />
</font></JFXButton>
<JFXButton id="menu-button" buttonType="FLAT" layoutX="269.0" layoutY="337.0" mnemonicParsing="false" onAction="#backToMenu" prefHeight="53.0" prefWidth="165.0" stylesheets="@css/style.css" text="Back" />
<Text fill="RED" layoutX="51.0" layoutY="455.0" strokeType="OUTSIDE" strokeWidth="0.0"
visible="false" fx:id="error" text="*Your username or password is not true!" textAlignment="CENTER" wrappingWidth="600.0">
<font>
<Font name="Ubuntu Light" size="25.0" />
</font>
</Text>
</children>
</Pane>
答案 0 :(得分:1)
stacktrace说:
Caused by: java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.valueOf(Unknown Source)
at sample.controller.LoginController.login(LoginController.java:29) ... 58 more
发生这种情况的语句是:
if (Integer.valueOf(SqlControl.isAccountEnabled(loginField.getText())) != 0)
您正在尝试将空字符串解析为整数。您的代码需要采取相关的预防措施以阻止这种情况的发生。