Exception in thread "Thread-2" java.lang.NullPointerException

Hi

I want to develop a lan messenger using java.

I have written a client code to interact with a server

it connects properly but as soon as i start a thread for listening

connection is ended. please suggest me on this....

below i m pasting my code and the error message

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.io.*;

import java.net.*;

import java.lang.*;

class interfaceclient

{

publicstaticvoid main(String args[])

{

TextInputFrame frame=new TextInputFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.show();

}

staticclass TextInputFrameextends JFrame

{

PrintWriter dout;

BufferedReader din;

JPanel panel=new JPanel();

JButton SendButton=new JButton("send");

JButton ExitButton=new JButton("exit");

JTextArea ta=new JTextArea(10,50);

JScrollPane scrollPane=new JScrollPane(ta);

JTextField tf=new JTextField(40);

public TextInputFrame()

{

setTitle("messenger");

setSize(WIDTH,HEIGHT);

Container contentPane=getContentPane();

panel.add(SendButton);

panel.add(ExitButton);

panel.add(tf);

contentPane.add(panel,BorderLayout.SOUTH);

panel.add(ta);

contentPane.add(scrollPane,BorderLayout.CENTER);

try

{

Socket cs=new Socket("localhost",7822);

BufferedReader din =new BufferedReader(new InputStreamReader(cs.getInputStream()));

PrintWriter dout=new PrintWriter(cs.getOutputStream(),true);

dout.println("hi server");

ta.setText("connected to server");

sockthread thread=new sockthread(cs);

thread.start();

SendButton.addActionListener(new action());

}catch(IOException ie){System.out.println("cant find server");}}

class actionimplements ActionListener

{

publicvoid actionPerformed(ActionEvent event)

{

try

{

String message=(tf.getText());

dout.println(message);

tf.setText("");

}

catch(Exception e)

{

System.out.println(e);

}

}

}

class sockthreadextends Thread

{private Socket cs;

public sockthread(Socket acs){cs=acs;}

publicvoid run()

{

try

{

dout.println("before while");

while(true)

{

dout.println("after while");

String mess=din.readLine();

ta.append("Server:"+mess+"\n");

}

}catch(IOException ie){System.out.println(ie);}

}

}

publicstaticfinalint WIDTH=600;

publicstaticfinalint HEIGHT=400;

}

}

the following error message is generated

Exception in thread"Thread-2" java.lang.NullPointerException

at interfaceclient$TextInputFrame$sockthread.run(Main.java:77)

java.lang.NullPointerException

java.lang.NullPointerException

java.lang.NullPointerException

BUILD SUCCESSFUL (total time: 23 seconds)

[6000 byte] By [Aditya-iiitma] at [2007-11-27 8:18:45]
# 1
The line number tells you the line the error occurred on.Null pointer exception tells you that something on that line is set to null rather than being set to a value.
jschella at 2007-7-12 20:07:03 > top of Java-index,Core,Core APIs...