Mistake when create 2 thread files in one program
<p>I have 2 thread file in a project of server: ThreadSocket and ThreadValidate.
ThreadSocket is used for sending and receiving information between client and server
ThreadValidate is used for testing an account in SignIn and SignUp form.</p>

<p>This is ThreadValidate:</p>

<pre><code>public class ThreadValidate extends Thread{
Socket socket;
String Username = null, Password = null;
BufferedReader inFromClient = null;
PrintWriter outToClient = null;

String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String databaseUrl = "jdbc:odbc:Driver={SQL Server};Server=abc-PC;Database=abc;UID=sa;PWD=";

public ThreadValidate(Socket pSocket){
    this.socket=pSocket;

}


public synchronized void run(){
    try{

        Class.forName(driver);
        Connection connection;
        connection = DriverManager.getConnection(databaseUrl);


        inFromClient = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        outToClient = new PrintWriter(socket.getOutputStream(), true);


        Username = inFromClient.readLine();
        Password = inFromClient.readLine();
        System.out.println(Username + " " + Password);
        //Đăng nhập
        String sqlSignIn = "SELECT * FROM UserDangNhap WHERE Username = ? AND Password = ?";
        // PreparedStatement
        PreparedStatement statementSignIn = connection.prepareStatement(sqlSignIn);

        statementSignIn.setString(1, Username);
        statementSignIn.setString(2, Password);

        ResultSet rsSignIn = statementSignIn.executeQuery();



        if (rsSignIn != null)
        {
            Username = rsSignIn.getString("Username");
            Password = rsSignIn.getString("Password");

            outToClient.println("exist");
        }
        else {
               outToClient.println("not exist");
        }
    } catch (ClassNotFoundException | SQLException | IOException ex){

    }
}
} 
</code></pre>

<p>and this is code in SignIn form:</p>

<pre><code>public class SignIn extends javax.swing.JFrame { 
    Socket socketValidate = null;
    private BufferedReader inValidate = null;
    private PrintWriter outValidate = null;
    public static String Username = null;
    public static String Password = null;
    public static String kq = ""; 

    public SignIn (java.awt.Frame parent, boolean modal) {
        initComponents();
        this.setResizable(false);
    }

    public SignIn (Socket client){
        this.socketValidate = client;
    }

    public void listenSocket() throws UnknownHostException {
        String serverAddress = "localhost";

        try {
             socketValidate = new Socket(serverAddress, 4444);
             inValidate = new BufferedReader(new InputStreamReader(socketValidate.getInputStream()));
             outValidate = new PrintWriter(socketValidate.getOutputStream(), true); 
         }
        catch  (IOException e)  {
            System.out.println("No I/O" + e.getMessage());
            System.exit(1);
        }
        catch (Exception ex) {
            System.out.println("Unknown host: " + serverAddress);
            System.exit(1);
        } 
    }


    private void bntdnActionPerformed(java.awt.event.ActionEvent evt) { 
        this.Username = txtUsername.getText();
        this.Password = txtPassword.getText();
        JOptionPane.showMessageDialog(this, Username + "   " + Password);

        outValidate.println(Username);
        outValidate.println(Password);

        try {
            kq = inValidate.readLine();
        } catch (IOException ex) {
            Logger.getLogger(DangNhap.class.getName()).log(Level.SEVERE, null, ex);
        }

        switch (kq) {
            case "exist":
                this.dispose();
                break;
            case "not exist":
                JOptionPane.showMessageDialog(this, "Retype again, please");
                break;
        } 
    }  
</code></pre>

<p>It shows error on these lines: <strong>outValidate.println(Username);
                               outValidate.println(Password);</strong>
 This is error</p>

<pre><code>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at client.SignIn .bntdnActionPerformed(SignIn .java:188)
at client.SignIn .access$000(SignIn .java:22)
at client.SignIn $1.actionPerformed(SignIn .java:102)
</code></pre>

<p>Please help me fix it, I don't understand the reason why. I can't send information which are username and password to ThreadValidate to process it. But the ThreadSocket.java is in project of server and GameClient.form is in project of client run ok. </p>

<p>Note: ThreadSocket and ThreadValidate are in the same project of server, GameClient and SignIn in the same project of client.</p>
