Hi, I have been asked to create a method to store information on the football players for the polish team. I have stored each player in an array of Players[]. My task is to output any players which match the search string. So the method I have to create is getAllContaining(String search). If any of the players match the name, their details are outputted.
I managed to do it fine in my Country class , the method looks like this :
public String getAllContainingName(String search){
String str = "";
for (Person p : squad) {
if ((p instanceof Player) || (p instanceof Manager)) {
if(p.matchByName(search) == true){
str += p.toString() + "\n";
}
}
}
return str;
}
Which correctly outputs the players if they match the string.
I then have to implement the same method but into a different class called Group.
My method looks like this:
public String getAllContaining(String search){
String str = "";
for(Country c : teams ){
str += c.getAllContainingName(search);
}
return str;
}
But the method does not work, it returns
Exception in thread "main" java.lang.NullPointerException
at hutchisonbarry.Group.getAllContaining(Group.java:50)
at hutchisonbarry.HutchisonBarry.main(HutchisonBarry.java:88)
Help is greatly appreciated thanks .