I have a class "Job" defined like this :

```
public class Job extends AbstractJob
{
    private String name;
    private String jobCount;
    private String status;
    private List<Job> children;

    public Job(String name, String jobCount, String status, List<Job> children) {
        this.name = name;
        this.jobCount = jobCount;
        this.status = status;
        this.children = children;
    }

    public String getName()
    {
        return name;
    }

    public String getJobCount()
    {
        return jobCount;
    }

    public String getStatus()
    {
        return status;
    }

    public List<Job> getChildren() {
        return children;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setJobCount(String jobCount) {
        this.jobCount = jobCount;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public void setChildren(List<Job> children) {
        this.children = children;
    }
}

```

What I would like to do is to be able to retrieve all the elements in a list of jobs including their children as well. Here's what I have done so far:

```
   public List<Job> getJobChildren(Job job) {

        List<Job> result = new ArrayList<Job>();
        if (job == null) {
            return new ArrayList<Job>();
        }
        List<Job> children = job.getChildren();
            for (Job k : children) {
                if (children != null && !children.isEmpty()) {
                    result.addAll(children);
                    getJobChildren(k);
                } else {
                    result.add(k);
                }
            }
            return result;
    }

```

In the main class, I instantiated and populated so jobs to test it, but I get a nullpointerException:

```
Job job2 = new Job("JOB0002","0002","Finished",null);
Job job3 = new Job("JOB0003","0003","Error",jobSubList);
Job job4 = new Job("JOB0004","0004","En cours",null);
jobSubList.add(job4);
List<Job> jobList = new ArrayList<Job>();
jobList.add(job2);
jobList.add(job3);
Job job = new Job("JOB0001","0001","En Cours",jobList);

```

I know why I'm getting the exception, but I'm not able to edit the method to make it return all the children.

The idea is to go through all the jobs and see if them too have jobs of their own. If they do, I go a level deeper and retrieve all those children, and I keep doing this until I retrieve all the jobs.

Could you please tell me what am I doing wrong in that method? 

Thank you.