I'm getting a null pointer exception on the join method with the addAll dogs line 51 and it wont print to screen why?
package com.codegym.task.task08.task0820;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/*
Animal set
*/
public class Solution {
public static void main(String[] args) {
Set<Cat> cats = createCats();
Set<Dog> dogs = createDogs();
Set<Object> pets = join(cats, dogs);
printPets(pets);
removeCats(pets, cats);
printPets(pets);
}
public static Set<Cat> createCats() {
HashSet<Cat> result = new HashSet<Cat>();
//write your code here
result.add(new Cat());
result.add(new Cat());
result.add(new Cat());
result.add(new Cat());
return result;
}
public static Set<Dog> createDogs() {
//write your code here
HashSet<Dog> dogHashSet = new HashSet<Dog>();
dogHashSet.add(new Dog());
dogHashSet.add(new Dog());
dogHashSet.add(new Dog());
return null;
}
public static Set<Object> join(Set<Cat> cats, Set<Dog> dogs) {
//write your code here
HashSet pets = new HashSet();
pets.addAll(cats);
pets.addAll(dogs);
return pets;
}
public static void removeCats(Set<Object> pets, Set<Cat> cats) {
//write your code here
for(Cat cat:cats){
pets.remove(cat);
}
}
public static void printPets(Set<Object> pets) {
//write your code here
for (Object pet : pets) {
System.out.println(pet);
}
}
//write your code here
public static class Cat{
Cat(){
}
}
public static class Dog{
Dog(){
}
}
}