Собственно, не пойму в чем проблема и почему выдает такую ошибку.
Ругается на 14,15,16,17,18,20, 22, 23 ,24.Ошибка именно в добавлении списка.
Менял местами детей, родителей и дедушек с бабушками - не помогло.
package com.javarush.task.task08.task0824;
/*
Собираем семейство
*/
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) {
ArrayList<Human> fa=new ArrayList<>();
ArrayList<Human> mo=new ArrayList<>();
ArrayList<Human> c=new ArrayList<>();
Human grandpa1 = new Human("ARwq", true, 61, fa);
Human grandpa3 = new Human("qwa", true, 63,mo);
Human grandma1 = new Human("asdvgq", false, 59, fa);
Human grandma3 = new Human("asdqw", false, 55, mo);
Human f = new Human("qwdxa", true, 31, c);
fa.add(f);
Human m = new Human("qwea", false, 30, c);
mo.add(m);
Human c1 = new Human("awqfqx", true, 18, new ArrayList<Human>());
Human c3 = new Human("qwqrs", false, 15, new ArrayList<Human>());
Human c5 = new Human("qweqw", true, 13, new ArrayList<Human>());
c.add(c1);
c.add(c3);
c.add(c5);//напишите тут ваш код
System.out.println(grandpa1);
System.out.println(grandpa3);
System.out.println(grandma1);
System.out.println(grandma3);
System.out.println(f);
System.out.println(m);
System.out.println(c1);
System.out.println(c3);
System.out.println(c5);
; }
public static class Human {
String name;
boolean sex;
int age;
ArrayList<Human> children=new ArrayList<>();//напишите тут ваш код
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;
}
}
}