all. I'm trying to get a value from a document, that looks like this:
{
"id" : player:(some number)",
"name" : "Martinez, Javi",
"type" : "midfielder",
"jersey_number" : 8,
"position" : "Central defender"
}
I have players in an ArrayList<Document> playersOnPitchHome
and want to find one with a particular "jersey_number"
My code (below), however, is giving me a NulPointerException in the row I've highlighted with the //here
comment. As far as I understand, the exception is not occuring due to me accessing playersOnPitchHome
The Code:
Document player = playersOnPitchHome.get(0);
int i;
for (i=0; i<playersOnPitchHome.size(); i++) {
player = playersOnPitchHome.get(i);
int numberTemp = (int) player.get("jersey_number"); //here
if (numberTemp == playerNumber) break;
if (i==(playersOnPitchHome.size()-1) && numberTemp != playerNumber) {
throw new Exception ("there is no such player on the pitch");
}
}
Thank you in advance.