• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with Head First Java simplechatclient -- NullPointerException

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .


 
Wanna see my flashlight? How about this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic