I am writing a login and registration program in java using MySQL.
When I call the register frame from the login frame, the register frame becomes visible but as soon as I click the "register" button after entering information, NullPointerException
occurs??
The interesting fact is the NullPointerException
doesn't occur if I open the register frame directly.
code is here:
void register() {
try {
String query ="insert into darkwebregister (CodeID,Email,Password,Age) values (?,?,?,?)";
pst = con.prepareStatement(query);
pst.setString( 1,idtext.getText());
pst.setString( 2,emailtext.getText());
pst.setString( 3,passtext.getText());
pst.setString( 4,agetext.getText());
pst.execute();
JOptionPane.showMessageDialog(null,"YOU ARE REGISTERED SUCESFULLY !!");
pst.close();
}catch(SQLException e1) {
Logger.getLogger(register.class.getName()).log(Level.SEVERE, null, e1);
}catch(Exception e2) {
JOptionPane.showMessageDialog(null, e2);
}
}
void createConnection() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hackersinfo","root","root");
}catch(Exception ex) {
JOptionPane.showMessageDialog( null, ex);
}
}