I have an ArrayList of Nodes. One of the fields of Node
class is level
.
I would like to find the level of the node that has the maximum level in the list.
This code gives me an NullPointerException...
private int findMaxLevel(ArrayList<Node> nodes)
{
int level = 0;
for(Node node : nodes)
{
if(node.getLevel() > level)
{
level = node.getLevel();
}
}
return level;
}
I've tried several implementations of this page : Sorting an ArrayList of Contacts based on name? but I didn't found the solution.
EDIT :
Thank you for your suggestions, the level should never be null but I've forgot to add this.level = level
in the Node
class constructor....