(Java) How to avoid null pointer exception when getting nested class element?
<p>I have a class like this one:</p>

<pre><code>class Tickets{
    Data data;
    class Data{
        String departure;
    }
    public String getDeparture(){
        return data.departure;
    }

}
</code></pre>

<p>When I try something like this:</p>

<pre><code>Tickets tickets=new Tickets();
if (tickets.getDeparture!=null)
</code></pre>

<p>I get nullpointerexception on this check. Why is that so? How can I avoid it? What to do instead?
Thanks for help.</p>