Добрый день уважаемые участники сайта JavaRush.
Требуется Ваш свежий взгляд. Вроде всё чисто, а последний пункт не отрабатывает.
Ошибку выдаёт такую, я пока читать и разбираться в ней не умею.
java.lang.NullPointerException
at com.javarush.task.task07.task0724.Solution$Human.<init>(Solution.java:48)
at com.javarush.task.task07.task0724.Solution.main(Solution.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
Благодарю за помощь и поддержку.
package com.javarush.task.task07.task0724;
/*
Семейная перепись
*/
public class Solution {
public static void main(String[] args) {
Human grandpa1 = new Human("George", true, 65);
Human grandpa2 = new Human("John", true, 62);
Human granny1 = new Human("Malva", false, 60);
Human granny2 = new Human("Silva", false, 59);
Human father = new Human("Berg", true, 36, grandpa1, granny1);
Human mother = new Human("Helen", false, 34, grandpa2, granny2);
Human son1 = new Human("Sergio", true, 12, father, mother);
Human son2 = new Human("Chuvak", true, 10, father, mother);
Human daughter = new Human("Berry", false, 8, father, mother);
System.out.println(grandpa1);
System.out.println(grandpa2);
System.out.println(granny1);
System.out.println(granny2);
System.out.println(father);
System.out.println(mother);
System.out.println(son1);
System.out.println(son2);
System.out.println(daughter);
}
public static class Human {
String name;
boolean sex;
int age;
Human father;
Human mother;
public Human(String name, boolean sex, int age) {
this.name = name;
this.sex = sex;
this.age = age;
}
public Human (String name, boolean sex, int age, Human father, Human mother) {
this.name = name;
this.sex = sex;
this.age = age;
this.father.name = name;
this.mother.name = name;
}
public String toString() {
String text = "";
text += "имя: " + this.name;
text += ", пол: " + (this.sex ? "мужской" : "женский");
text += ", возраст: " + this.age;
if (this.father != null) {
text += ", отец: " + this.father;
}
if (this.mother != null) {
text += ", мать: " + this.mother;
}
return text;
}
}
}