java - Nullpointer in a strange place -



java - Nullpointer in a strange place -

i can not understand how perchance throw nullpointer exception. code follows:

if (gameservers.isempty()) { homecoming false; } int freeslots = integer.min_value; gameserver chosenone = null; (gameserver gs : gameservers) { if (gs.getslots() > freeslots) { // line throws nullpointer exception freeslots = gs.getslots(); chosenone = gs; } }

where gs.getslots() simple return this.slots(of type int). gameservers arraylist filled new gameserver(..., ..., slots) objects, can't homecoming null either.

can tell me begin looking?

you need check if gs null in loop, like

if(gs != null && <insert original if statement>){ ....

java nullpointerexception

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -