• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nullpointerexception in Thread

 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Henry Wong
author
Marshal
Pie
Posts: 20882
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Henry
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, you are right!! (how embarrassing! Is it possible to delete this thread?)
 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
himanshu.harish agrawal
Ranch Hand
Posts: 47
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic