При переходе в это окно кидает java.lang.reflect.InvocationTargetException и Caused by: java.lang.NullPointerException: Cannot invoke "javafx.scene.control.Button.setOnAction(javafx.event.EventHandler)" because "this.backButton" is null
package com.example.myapp;
import java.net.URL;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
// ОКНО АВТОРИЗАЦИИ
public class app6Controller {
@FXML
private ResourceBundle resources;
@FXML
private URL location;
@FXML
private Button ExitButton;
@FXML
private TextField LoginField;
@FXML
private PasswordField PasswordField;
@FXML
private Button regButton;
@FXML
private Button signButton;
@FXML
void initialize() {
signButton.setOnAction(event -> {
String login = LoginField.getText().trim();
String password = PasswordField.getText().trim();
if(login.equals("") && password.equals("")){
loginUser(login, password);
} else {
System.out.println("Error");
}
});
}
private void loginUser(String login, String password) {
DataBaseHandler dataBaseHandler = new DataBaseHandler();
User user = new User();
user.setLogin(login);
user.setPassword(password);
ResultSet resultSet = dataBaseHandler.getUser(user);
int count = 0;
while (true){
try {
if (!resultSet.next()) break;
} catch (SQLException e) {
e.printStackTrace();
}
count++;
}
if(count >= 1){
System.out.println("Success");
}
}
}
И его fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="497.0" prefWidth="700.0" style="-fx-background-color: #2E3349; -fx-border-radius: 10;" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.myapp.app3Controller">
<children>
<AnchorPane layoutX="-8.0" layoutY="85.0" prefHeight="419.0" prefWidth="708.0" style="-fx-background-color: #fafafa; -fx-border-radius: 5;">
<children>
<Button fx:id="signButton" layoutX="558.0" layoutY="363.0" mnemonicParsing="false" prefHeight="45.0" prefWidth="137.0" style="-fx-background-color: #ffcc66; -fx-background-radius: 0;" text="Войти">
<font>
<Font name="ft40 Roman" size="16.0" />
</font>
</Button>
<Label layoutX="14.0" layoutY="363.0" prefHeight="45.0" prefWidth="317.0" text="Авторизация">
<font>
<Font name="ft40 Roman" size="44.0" />
</font>
</Label>
<Label layoutX="23.0" layoutY="349.0" opacity="0.13" prefHeight="45.0" prefWidth="317.0" text="Авторизация">
<font>
<Font name="ft40 Roman" size="44.0" />
</font>
</Label>
<Label layoutX="175.0" layoutY="14.0" prefHeight="77.0" prefWidth="374.0" text="Введите ваш ник:">
<font>
<Font name="ft40 Roman" size="40.0" />
</font>
</Label>
<TextField fx:id="LoginField" layoutX="216.0" layoutY="98.0" prefHeight="37.0" prefWidth="277.0" promptText="Fareny">
<font>
<Font name="ft40 Roman" size="20.0" />
</font>
</TextField>
<PasswordField fx:id="PasswordField" layoutX="216.0" layoutY="222.0" prefHeight="37.0" prefWidth="277.0" promptText="123456789">
<font>
<Font name="ft40 Roman" size="15.0" />
</font>
</PasswordField>
<Label layoutX="185.0" layoutY="146.0" prefHeight="57.0" prefWidth="354.0" text="Введите пароль:">
<font>
<Font name="ft40 Roman" size="40.0" />
</font>
</Label>
<Button fx:id="regButton" layoutX="358.0" layoutY="363.0" mnemonicParsing="false" prefHeight="45.0" prefWidth="200.0" style="-fx-background-radius: 0; -fx-background-color: #2E3349;" text="Зарегистрироваться" textFill="WHITE">
<font>
<Font name="ft40 Roman" size="16.0" />
</font>
</Button>
</children>
</AnchorPane>
<Label layoutX="14.0" layoutY="10.0" prefHeight="45.0" prefWidth="189.0" text="MineHelper" textFill="WHITE">
<font>
<Font name="ft40 Roman" size="30.0" />
</font>
</Label>
<Button fx:id="ExitButton" layoutX="558.0" layoutY="15.0" mnemonicParsing="false" prefHeight="37.0" prefWidth="128.0" style="-fx-background-color: #ffcc66;" text="Exit">
<font>
<Font name="ft40 Roman" size="18.0" />
</font>
</Button>
</children>
<cursor>
<Cursor fx:constant="DEFAULT" />
</cursor>
</AnchorPane>
backButtonне встречается нигде в показанном коде. Если эта переменная установлена вnull, значит она не была корректно проинициализирована. – Nowhere Man Jan 05 '22 at 12:44