wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Nullpointerexception in Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Nullpointerexception in Thread" Watch "Nullpointerexception in Thread" New topic
Author

Nullpointerexception in Thread

John Eipe
Ranch Hand

Joined: May 23, 2008
Posts: 215
Hi,

I was reading concept of Synchronized methods at this link:
http://download.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html
improvised the code there.


I'm getting the below error when I run,

Exception in thread "John" mainquits
java.lang.NullPointerException
at Spawn.run(s8.java:45)
at java.lang.Thread.run(Thread.java:636)
Exception in thread "Thomas" java.lang.NullPointerException
at Spawn.run(s8.java:45)
at java.lang.Thread.run(Thread.java:636)

www.cs-repository.info
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18914
    
  40


Your Spawn class never actually instantiated a SynCounter object -- so when it tries to use it, it gets a NPE.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
John Eipe
Ranch Hand

Joined: May 23, 2008
Posts: 215
yes, you are right!! (how embarrassing! Is it possible to delete this thread?)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19725
    
  20

Nope, afraid not. But don't worry, everybody makes this mistake at least once. Anyone who says differently is lying, or hasn't got to that point yet


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
himanshu.harish agrawal
Ranch Hand

Joined: Oct 18, 2010
Posts: 47

Correct, not to worry, not everybody is lucky enough to become successful without relishing the taste of failure ..

same way, not everybody is lucky enough to become a good Java developer without getting null pointers.
 
jQuery in Action, 2nd edition
 
subject: Nullpointerexception in Thread