Why the 'Null-pointer exception" is raised?
<p>I'm trying to implement an interface, but I get the 'Null-pointer' exception, but I don't know why and I don't know how to avoid it.</p>

<p>class SpaceComposite.java</p>

<pre><code>import java.util.List;
public class SpaceComposite extends SpaceComponent implements ISpaceComposite {

    private List&lt;ISpaceComponent&gt; _components;

    public SpaceComposite(String _title) {
        super(_title);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void addComponent(ISpaceComponent component) {
        _components.add(component);// HERE IS THE EXCEPTION RAISED

    }
}
</code></pre>

<p>which derrives from SpaceComponent class</p>

<pre><code>public abstract class SpaceComponent implements ISpaceComponent{
private String _title;

public SpaceComponent(String _title) {
    super();
    setTitle( _title);
}
</code></pre>

<p>interface ISpaceComposite derrives from ISpaceComponent</p>

<pre><code>public interface ISpaceComposite extends ISpaceComponent{
    public void addComponent(ISpaceComponent component);

}


public interface ISpaceComponent {
    // Title getter/setter
        String getTitle();
        void setTitle(String title);

    // Looking for a specific child
        ISpaceComponent findChild(String name);

    // We need to test this brave new world
    void runTtest();
}
</code></pre>

<p>class Demo.class tries to create a SpaceComposite</p>

<pre><code>public static ISpaceComposite createSolarSystem() {

    ISpaceComposite solarSystem = new SpaceComposite("The Solar System");

    Star theSol = new Star("Sol");
    solarSystem.addComponent(theSol);
}
</code></pre>

<p>This line generates the exception </p>

<pre><code>public void addComponent(ISpaceComponent component) {
    _components.add(component);// HERE IS THE EXCEPTION RAISED

}
</code></pre>

<p>but the component 'component' is passed to the function, and i can't look to the List class.</p>

<p>Do you know, what am I doing wrong?</p>

<p>P.S. This code was adopted from C# .NET and in the .NET there is no mistakes..</p>

<p>P.P.S. Guys! You're right! But so many correct answers.... Really confused, which I should to mark</p>
