java netbeans 7.01中的swing注册表单空指针异常

s2j5cfk0  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(175)

我已经为自己的项目创建了一个注册表。它在我执行代码时成功运行。但是当我填写表单并单击登录按钮时,它会提示消息 java.lang.NullPointerException . 我怎样才能解决这个问题?
这是我的密码:

import javax.swing.*;
import java.sql.*;

public class SignUp extends javax.swing.JFrame {

    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    /**Creates new form SignUp */
    public SignUp() {
        initComponents();

        conn = connection.connectDB();

    }
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

    if (evt.getSource() == jButton1)
         {
            int x = 0;
            String s1 = jTextField1.getText();
            String s2 = jTextField2.getText();

            char[] s3 = jPasswordField1.getPassword();
            char[] s4 = jPasswordField2.getPassword(); 
            String s8 = new String(s3);
            String s9 = new String(s4);

            String s5 = jTextField5.getText();
            String s6 = jTextField6.getText();
            String s7 = jTextField7.getText();

            if(s8.equals(s9))
            {
                try
                {
                PreparedStatement Ps = conn.prepareStatement("insert into registration values(?,?,?,?,?,?)");
                    ps.setString(1, s1);
                    ps.setString(2, s2);
                    ps.setString(3, s8);
                    ps.setString(4, s5);
                    ps.setString(5, s6);
                    ps.setString(6, s7);
                    ResultSet rs = ps.executeQuery();
                    x++;
                    if (x > 0) 
                    {
                        JOptionPane.showMessageDialog(jButton1, "Data Saved Successfully");
                    }
                }
                catch(Exception e)
                {
                    System.out.println(e);
                }
            }
            else
            {
                JOptionPane.showMessageDialog(jButton1, "Password Dosn't match");
            }

    }
     else
    {
        jTextField1.setText("");
            jTextField2.setText("");
            jPasswordField1.setText("");
            jPasswordField2.setText("");
            jTextField5.setText("");
            jTextField6.setText("");
            jTextField7.setText("");
    }

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题