| Author |
Nullpointerexception in Thread
|
John Eipe
Ranch Hand
Joined: May 23, 2008
Posts: 205
|
|
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: 16680
|
|
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: 205
|
|
yes, you are right!! (how embarrassing! Is it possible to delete this thread?)
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19214
|
|
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
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.
|
 |
 |
|
|
subject: Nullpointerexception in Thread
|
|
|