I have a small but very annoying bug.
Actually I am programming a family tree and some cases I search for a person but sometimes the person is not in the tree (makes sense). So my methods returns null.
The problem is when I try to do something like this.
familytree.getNode("Peter").getName();
Peter is not in the tree however he tries to get the Name and my code gives me a NullPointerException
(makes sense again).
Though I dont know how to handle this kind of problem, I have a lot similar methods like getName()... For Example getGender(), getWife() etc.
I have two classes the familytree(with search, delete, etc. methods) and node (with all information about the person).
Maybe you guys have an idea!
EDIT:
For example this is my main method;
familytree.getNode("Fred").getGender(); //boolean
familytree.getNode("Max").getGender();
familytree.getNode("Peter").getGender();
familytree.getNode("Fe").getPartner(); //Partner Name
familytree.getNode("Freddyy").getName(); //String
How do I check for every case if its a nullpointer?