Exception in thread "main" java.lang.NullPointerException
at com.javarush.task.task08.task0824.Solution$Human.<init>(Solution.java:59)
at com.javarush.task.task08.task0824.Solution.main(Solution.java:15)
Ребята, что не так с этим кодом? Подскажите, пожалуйста.
package com.javarush.task.task08.task0824;
/*
Собираем семейство
*/
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) {
//напишите тут ваш код
Human child1 = new Human("rebenok1", false, 20);
Human child2 = new Human("rebenok2", true, 15);
Human child3 = new Human("rebenok1", false, 10);
Human father = new Human("papa", true, 45, child1, child2, child3);
Human mother = new Human("mama", false, 40, child1, child2, child3);
Human fatherOfFather = new Human("papa papi", true, 80, father);
Human motherOfFather = new Human("mama papi", false, 75, father);
Human fatherOfMother = new Human("papa mami", true, 70, mother);
Human motherOfMother = new Human("mama mami", false, 65, mother);
System.out.println(fatherOfFather);
System.out.println(motherOfFather);
System.out.println(fatherOfMother);
System.out.println(motherOfMother);
System.out.println(father);
System.out.println(mother);
System.out.println(child1);
System.out.println(child2);
System.out.println(child3);
}
public static class Human {
//напишите тут ваш код
String name;
boolean sex;
int age;
ArrayList<Human> children;
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 child) {
this.name = name;
this.sex = sex;
this.age = age;
this.children.add(child);
}
public Human (String name, boolean sex, int age, Human child1, Human child2, Human child3) {
this.name = name;
this.sex = sex;
this.age = age;
this.children.add(child1);
this.children.add(child2);
this.children.add(child3);
}
public String toString() {
String text = "";
text += "Имя: " + this.name;
text += ", пол: " + (this.sex ? "мужской" : "женский");
text += ", возраст: " + this.age;
int childCount = this.children.size();
if (childCount > 0) {
text += ", дети: " + this.children.get(0).name;
for (int i = 1; i < childCount; i++) {
Human child = this.children.get(i);
text += ", " + child.name;
}
}
return text;
}
}
}