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 Beginning Java and the fly likes NullPointerException with a foreach statement? 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 » Java » Beginning Java
Bookmark "NullPointerException with a foreach statement?" Watch "NullPointerException with a foreach statement?" New topic

NullPointerException with a foreach statement?

Josh Rodrigues

Joined: Apr 14, 2010
Posts: 17
Hi, I'm trying to execute a method in a different class called loadCriteria();. Whenever I try to execute that method, it returns a NullPointerException. I'm not sure why and I've used a foreach loop before.

Sorry for it being so long. The NullPointerException occurs at "p.loadCriteria();". The player instance is being called correctly, so I'm not sure why it's nulling. Help is appreciated. Thanks.
pete stein

Joined: Feb 23, 2007
Posts: 1561
Do you know for a fact that none of the Player objects held in Server.playerHandler.players are null?
Rob Spoor

Joined: Oct 27, 2005
Posts: 19649

And are you sure that neither Server.playerHandler and Server.playerHandler.players are null?

How To Ask Questions How To Answer Questions
Nitesh Kant

Joined: Feb 25, 2007
Posts: 1638

CarefullyChooseOneForum while posting. Moving to Beginning java forum.

apigee, a better way to API!
I agree. Here's the link:
subject: NullPointerException with a foreach statement?
Similar Threads
Please need help with calculator program...
Need help with Mini Telephone Directoy program please
Issue while invoking JNDI in a JMS example in glassfish
ConcurrentModificationException driving me nuts.
Synchronize the way threads(players) take their turn.