所有。 我试图从文档中获取一个值,如下所示:
{
"id" : player:(some number)",
"name" : "Martinez, Javi",
"type" : "midfielder",
"jersey_number" : 8,
"position" : "Central defender"
}
我有ArrayList<Document> playersOnPitchHome
的玩家,想要找到具有特定"jersey_number"
的玩家
然而,我的代码(下面)在我用//here
评论突出显示的行中给了我一个NulPointerException。据我了解,由于我访问playersOnPitchHome
守则:
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");
}
}
提前谢谢。