This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes SOS: i have some questions about Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "SOS: i have some questions about Thread" Watch "SOS: i have some questions about Thread" New topic
Author

SOS: i have some questions about Thread

kevin saber
Greenhorn

Joined: Mar 07, 2010
Posts: 21


this will cause NullPointerException when i run it, but i don't understand why...
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

In the go method, the two Test5 objects with which you create 2 threads both have Chicks as null, so calling yack in the run method causes NPE. Try this


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
kevin saber
Greenhorn

Joined: Mar 07, 2010
Posts: 21
oh~~ i would have simply thought that c have pointed to an object by mistake as line 9 showed.
thank you!!!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SOS: i have some questions about Thread
 
Similar Threads
Thread synchonization
Confusion with this Output
Using non-static object as lock in Threads PRoblem
Question on multithreading from Sierra/Bates Chapter 9, Question 16
Thread.yield()