title: ResultSet could be possibly null, how to fix this?
body: <p>It tells me that the &quot;userRow&quot; ResultSet could be null, do you guys know how can I fix this or why is it happening, I would greatly appreciate it, thanks.</p>
  <p>It tells me to add more details: I created this ResultSet method in order to retrieve information from the MySQL database that I made with MySQL Workbench, I'm trying to retrieve the information of the USER_TABLE, username, and password, so it would get the info from these two columns and then check with the database and allow the login. But it has been giving me the exception that the ResultSet might be null, I also indicated the specific location of the error right in the code.</p>
  <p>Any kind of help is appreciated.</p>
  <p>Thanks.</p>
  <p>here are my two classes involved with the issue:</p>
  <pre><code>public class Login {
  
  @FXML
  private TextField userNameTextField;
  
  @FXML
  private PasswordField passwordPasswordField;
  
  @FXML
  private Button signUpButton;
  
  @FXML
  private Button loginButton;
  
  private sample.database.dbHandler dbHandler;
  
  @FXML
  void initialize() {
  
      dbHandler = new dbHandler();
  
  
      loginButton.setOnAction(event -&gt; {
  
          String loginText = userNameTextField.getText().trim();
          String loginPassword = passwordPasswordField.getText().trim();
  
          User user = new User();
          user.setUsername(loginText);
          user.setPassword(loginPassword);
  
          ResultSet userRow = dbHandler.getUser(user);
  
          int counter = 0;
  
          try {
  
              while (userRow.next()) { //it says that &quot;userRow&quot; could possibly be null
  
                  counter++;
  
              }
  
              if (counter == 1) {
  
                  System.out.println(&quot;Logged in&quot;);
  
              }
  
          } catch (SQLException e) {
  
              e.printStackTrace();
  
          }
  
      });
  
      signUpButton.setOnAction(event -&gt; {
  
          signUpButton.getScene().getWindow().hide();
  
          FXMLLoader loader = new FXMLLoader();
          loader.setLocation(getClass().getResource(&quot;/sample/signup.fxml&quot;));
  
          try {
  
              loader.load();
  
          } catch (IOException e) {
  
              e.printStackTrace();
  
          }
  
          Parent root = loader.getRoot();
          Stage stage = new Stage();
          stage.setScene(new Scene(root));
          stage.showAndWait();
  
      });
  
  }
  </code></pre>
  <hr />
  <pre><code>public class dbHandler extends Config {
  
  java.sql.Connection Connection;
  
  public Connection getConnection() throws ClassNotFoundException, SQLException {
  
      String connectionString = &quot;jdbc:mysql://&quot; + dbHost + &quot;:&quot; + dbPort + &quot;/&quot; + dbName;
  
      Class.forName(&quot;com.mysql.cj.jdbc.Driver&quot;);
  
      Connection = DriverManager.getConnection(connectionString, dbUser, dbPass);
  
      return Connection;
  
  }
  
  public void signUp(User user) {
  
      String insert = &quot;INSERT INTO &quot; + Constants.USERS_TABLE + &quot;(&quot; + Constants.USERS_FIRSTNAME + &quot;,&quot; + Constants.USERS_LASTNAME + &quot;,&quot; +
              Constants.USERS_USERNAME + &quot;,&quot; + Constants.USERS_PASSWORD + &quot;)&quot; + &quot;VALUES(?,?,?,?)&quot;;
  
      try {
  
          PreparedStatement preparedStatement = getConnection().prepareStatement(insert);
  
          preparedStatement.setString(1, user.getFirstName());
          preparedStatement.setString(2, user.getLastName());
          preparedStatement.setString(3, user.getUsername());
          preparedStatement.setString(4, user.getPassword());
  
          preparedStatement.executeUpdate();
  
      } catch (SQLException e) {
  
          e.printStackTrace();
  
      } catch (ClassNotFoundException e) {
  
          e.printStackTrace();
  
      }
  
  }
  
  public ResultSet getUser(User user) {
  
      ResultSet resultSet = null;
  
      if (!user.getUsername().equals(&quot;&quot;) || !user.getPassword().equals(&quot;&quot;)) {
  
          String query = &quot;SELECT * FROM &quot; + Constants.USERS_TABLE + &quot; WHERE &quot; + Constants.USERS_USERNAME + &quot;=?&quot;
                  + &quot; AND &quot; + Constants.USERS_PASSWORD + &quot;=?&quot;;
  
      try {
  
          PreparedStatement preparedStatement = getConnection().prepareStatement(query);
          preparedStatement.setString(1, user.getUsername());
          preparedStatement.setString(2, user.getPassword());
  
          preparedStatement.executeQuery();
  
      } catch (SQLException e) {
  
          e.printStackTrace();
  
      } catch (ClassNotFoundException e) {
  
          e.printStackTrace();
  
      }
  
      } else {
  
          System.out.println(&quot;Error&quot;);
  
      }
  
      return resultSet;
  
  }
  </code></pre>