getActionBar returning null
<p>I have a activity</p>

<p>and I have added </p>

<pre><code> setSupportActionBar(toolbar);
</code></pre>

<p>And I want to display home button on action bar.
Home button is from android predefined.</p>

<p>And I am calling this method</p>

<pre><code>getActionBar().setDisplayHomeAsUpEnabled(true);
</code></pre>

<p>But when I run the app, it gives that getActionBar retured <code>null</code></p>

<p>Full code of activity is following</p>

<pre><code> @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

    setSupportActionBar(toolbar);


    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    . setAction("Action", null).show();
        }
    });



    getActionBar().setDisplayHomeAsUpEnabled(true);
</code></pre>

<p>Why getActionBar returning null? thats my question.</p>