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!