This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Testing and the fly likes JUnit giving null pointer exception but temp variable fixes exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "JUnit giving null pointer exception but temp variable fixes exception" Watch "JUnit giving null pointer exception but temp variable fixes exception" New topic
Author

JUnit giving null pointer exception but temp variable fixes exception

Gulshan Singh
Ranch Hand

Joined: Apr 22, 2009
Posts: 41
The relevant code is:


All variables used have been initialized; that's not the problem.
This test gives me a null pointer exception at the first verify line:


But this test works:


Why does the second test work?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32508
    
214

Looks like you already got an answer on StackOverflow. Cross posting is fine although we do recommend you link between the posts so people know when it has been answered.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
 
Have you checked out Aspose?
 
subject: JUnit giving null pointer exception but temp variable fixes exception
 
It's not a secret anymore!