Re: please help to debug error
darker side wrote:
I tried to execute following client server program.
> [ ... ]
public class cli
public static void main(String args) throws IOException
Socket cli=new Socket(InetAddress.getByName("localhost"),1233);
System.out.println("connected by client");
DataInputStream dis=new DataInputStream(System.in);
DataOutputStream dos=new DataOutputStream(cli.getOutputStream());
What do you think this method is doing? Look at it carefully, since
there is something that most people would logically expect it to do but
it doesn't do...
In addition, you should explicitly close the Socket when you are
finished using it.
Exception in thread "main" java.lang.NullPointerException
There is only one reason why the constructor of String would throw a
NullPointerException: the String being passed in is null. Now, ask
yourself why the input from the socket is null (hint: look at your
client class. What isn't it doing?).
please help me to solve this problem and tell me reason why it happens
Some other points-of-order:
@ Don't use tab's in Usenet posts. It screws up formatting.
@ Use proper English grammar, including capitalization and punctuation.
@ It generally helps to go through the Java APIs if you need help.
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth