public static void main(String[] args) {
ChatApplication program=new ChatApplication();
program.createInterface();
}
I see, You do all stream initialisation in the parameterized ctor (constructor) but you are calling the default ctor. Every thing is kept null so, NullPointerException.
Now here
sendButton.addActionListener(this);
connectButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String userName=JOptionPane.showInputDialog(window,"Name: "," ",JOptionPane.PLAIN_MESSAGE);
try{
String serverName="localhost";
new ChatApplication(userName, serverName);
window.setTitle(userName);
}catch(IOException ex){
JOptionPane.showMessageDialog(window,"Clientul nu se poate conecta."+ex.getMessage().toString());
}
}
});
Here you call the required ctor and start a thread, the ctor, initializes the streams and hence the calls are fine.
PS: Your UI is messy, do some homework.