This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to fix null pointer in this situation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to fix null pointer in this situation" Watch "How to fix null pointer in this situation" New topic
Author

How to fix null pointer in this situation

raj talatam
Ranch Hand

Joined: Apr 19, 2012
Posts: 80


if first client gets failed next one also not getting output how to fix this problem


Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7081
    
  16

raj talatam wrote:if first client gets failed next one also not getting output how to fix this problem

First, please TellTheDetails (←click). In this case, the stack trace would be useful. If it's huge, just give the first 10 lines or so.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19557
    
  16

On line 59 you explicitly throw this NullPointerException. I have no idea why though.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

raj talatam wrote:
ts.registerObserver(printMedia);
ts.registerObserver(onlineMedia);
if first client gets failed next one also not getting output how to fix this problem

rearrange the subscribing sequence..

Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4246
    
    7

I assume the idea is for a failing observer not to cause following observers to be skipped, and the explicitly thrown exception is a test. In which case, put a try/catch block around the code that notifies the individual observers.

I'd question whether it's a great idea, though. Any NullPointerException should be a bug, and the best way to handle it is to fix it!
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

Matthew Brown wrote:I assume the idea is for a failing observer not to cause following observers to be skipped, and the explicitly thrown exception is a test. In which case, put a try/catch block around the code that notifies the individual observers.

I'd question whether it's a great idea, though. Any NullPointerException should be a bug, and the best way to handle it is to fix it!


I second Matthew over here. I remember when I started programming, my Lead used to say that getting a NullPointerException is a SIN and if it is your code, then you are a SINNER!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to fix null pointer in this situation
 
Similar Threads
Refreshable List (really tough question)
Queueing of call in GWT
Repainting JInternal Frames
"Static reference to non-static method"
Observer Example