Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

thread nullpointerexception

Thread view: 
rajatag - 20 Oct 2005 03:30 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.