1

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.

enter image description here

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);
         }
    }
Rohde Fischer
  • 1,248
  • 2
  • 10
  • 32
  • 1
    Can you please share the NPE stack trace as well. – Pbd Apr 24 '20 at 07:50
  • 1
    Don't post images. Paste your code in here – Kalana Apr 24 '20 at 08:18
  • java.lang.NullPointerException at loginform.register.registernow(register.java:186) at loginform.register$2.actionPerformed(register.java:126) at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967) at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308) at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405) – BIKASH OJHA Apr 24 '20 at 10:58
  • What is in the line 186 of your file register.java ? – sanastasiadis Apr 24 '20 at 11:07
  • Also, where is line 126? That is where the ActionPerfomed handler is located. – NomadMaker Apr 25 '20 at 16:21
  • Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Progman Apr 25 '20 at 20:03

0 Answers0