This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Help with Head First Java simplechatclient -- NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Help with Head First Java simplechatclient -- NullPointerException" Watch "Help with Head First Java simplechatclient -- NullPointerException" New topic
Author

Help with Head First Java simplechatclient -- NullPointerException

Rafael Szlom
Greenhorn

Joined: Jan 29, 2012
Posts: 2
Hi gyus,
first time poster here.

I tried to run the sample code from chapter 18 / Head first Java and get the following error message.

Exception in thread "Thread-0" java.lang.NullPointerException
at chatclient2.ChatClient2$MessageReader.run(ChatClient2.java:97)
at java.lang.Thread.run(Thread.java:722)


Here is the Full sourcecode




Could anyone please help me out. The problem lies in while((message = reader.readLine() != null) / Line 97

Don
Rajesh Nagaraju
Ranch Hand

Joined: Nov 27, 2003
Posts: 57
If you run the program directly it gives first the following exception

Problem: java.net.ConnectException: Connection refused: connect


I am assuming you get this exception, this is because you dont have a
socket open at your local system at port 5000

This leads to a NullPointerException later

Hope this helps
Rafael Szlom
Greenhorn

Joined: Jan 29, 2012
Posts: 2
Thank you Rajesh ,

you will not believe it , I did not start the method responsible for setting up the networking in the server code.
by the way that was exactly the same error message that I got .


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with Head First Java simplechatclient -- NullPointerException
 
Similar Threads
While loop problem
Best way for login authentication
Usability features
I need help improving this chat server and chat client!
How do you formally disconect a client from a server?