Hello,
I have a java chat server where each client that connects gets a new
thread.
The server runs fine most of the time but generally after a few hours
it generates a NullPointerException in the client thread and crashes
the entire server.
Any ideas why this could be happening? Or, any other information I can
supply so someone can help me out?
Thanks,
Rajat
Roedy Green - 20 Oct 2005 03:49 GMT
>The server runs fine most of the time but generally after a few hours
>it generates a NullPointerException in the client thread and crashes
>the entire server.
You have given us nothing to go on. To track it down, see
http://mindprod.com/jgloss/runerrormessages.html#NULLPOINTEREXCEPTION

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
zero - 20 Oct 2005 14:29 GMT
"rajatag" <rjsoftwares@gmail.com> wrote in news:1129775564.368084.302470
@o13g2000cwo.googlegroups.com:
> Hello,
>
[quoted text clipped - 7 lines]
> Any ideas why this could be happening? Or, any other information I can
> supply so someone can help me out?
On line 135 of MyProg.java change the i to j.
Seriously, with your explanation we can't begin to guess what's wrong (well
ok we could guess that you're forgetting to initialize a variable). A
stacktrace would be a good start, and the code that generates the error.
Tor Iver Wilhelmsen - 21 Oct 2005 17:13 GMT
> Any ideas why this could be happening?
In 99 percent of cases, it's thrown by the VM when you try to use the
dot operator on a null reference. E.g. foo.someMethod() when foo is
null.
That is all the help we can give with the pithy information you have
given.
rajatag - 24 Oct 2005 14:59 GMT
Hi,
Thank you for the replies. The source code is under an NDA so I can't
give that out, but here's a further explanation as I managed to figure
out when the problem occurs:
1. Chat server runs in a thread of its own.
2. Clients connect to the server via TCP and get their own threads.
This Client Class has a "finally" block in the run method where it runs
some cleanup code including letting other users know that this client
has now disconnected.
3. The problem happens when a dialup user gets disconnected. It seems
that by the team the code in the finally block has executed, the thread
itself is no longer available and has become "null". As a result of
this we get those exceptions.
Is that possible? If yes, what should the alternative be? Have all the
"finally" block code written in the server thread?
Thanks,
Rajat