I'm new to android. Been working with these action bars lately.
I used this following code on my mainActivity's onCreat()
import android.support.v7.app.ActionBar;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setIcon(R.mipmap.ic_launcher_round);
}
and it works But if I use this code
import android.ActionBar;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setIcon(R.mipmap.ic_launcher_round);
}
It creates a Null pointer exception
at setDisplayShowHomeEnabled()
.
Due to that the getActionBar()
returning Null
.
Can anyone say the reason behind this.?
Thanks.