0

I'm using JavaFX for my application's GUI.

     public void testUsername(KeyEvent ke) throws SQLException{
            if (ke.getCode().equals(KeyCode.ENTER))
    {
        if(checkUsernameInDataBase(txtUsername.getText())==false)
        {

              Image image = new Image(getClass().getResourceAsStream("Z6if3PZ.png"));
                lblImage.setGraphic(new ImageView(image));
        }
    }
}







public boolean checkUsernameInDataBase(String username) throws SQLException {
    // verific daca username introdus este sau nu in baza de date
    // daca este deja returnez true altfel returnez false
    // daca e true nu se poate face signUp daca e false se poate

    String usrCheckStr = String.format("select * from utilizatori where username = '" + username + "'");
    ResultSet results = DBMain.getStatement().executeQuery(usrCheckStr);

    if (!results.isBeforeFirst()) {
        // results.isBeforeFirst verifica daca curosorul se afla inainte de
        // primul rezultat
        // si intoarce true daca este acolo sau false daca nu este
        // daca intoarce false inseamna ca nu exista inregistrari
        // deci username nu exista in baza de date
        return false;
    } else

        return true;



}

Could someone tell me why i receive NullPointerException when i am using checkUserNameInDataBase method? This method looks in a DataBase if current Username exits. Ideea is that when i am using it in a main method, it works, but when i am trying to use it in the testUsername method, i receive error. Thx!

Sebi95
  • 161
  • 4
  • 13
  • 1
    Which line throws the null pointer exception? Which value is null? – James_D Apr 02 '16 at 23:24
  • Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – fabian Apr 03 '16 at 02:08

0 Answers0