当我点击我的程序中一个应该将数据发送到数据库的按钮时,我收到此错误:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
... 108 more
Caused by: java.lang.NullPointerException
at controller.RegisterController.reg(RegisterController.java:23)
... 60 more
以下是代码本身的一部分:
package controller;
public class RegisterController {
public void initialize() {}
public void reg(){
String gender = null;
line 23 ----> if(radioMale.isPressed()){
gender = "male";
}
if(radioFemale.isPressed()){
gender = "female";
}
String query = "INSERT INTO Main (USERNAME,PASSWORD,BirthDate,Gender) VALUES (" + "'" + username.getText() +
"'," + "'" + password.getText() + "'," + "'" + date_picker.getValue() + "'," + "'" + gender + "');";
insertStatement(query);
}
P.S。我从代码和错误中删除了很多,因为该网站没有让我发布这么多代码。但我相信这个问题应该在某处