• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Nullpointerexception in Thread

 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, you are right!! (how embarrassing! Is it possible to delete this thread?)
 
Sheriff
Posts: 22650
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 47
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
A magnificient life is loaded with tough challenges. En garde tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic