Skip to content Skip to sidebar Skip to footer

Null Pointer Exception At Action Bar

I am getting null pointer exception at action bar. I am using getActionBar().Following are the errors..I am extending Activity java.lang.RuntimeException: Unable to start activity

Solution 1:

if you are using Activity then use below code

ActionBaractionBar= getActionBar();
actionBar.hide();

or you are using ActionBarActivity then getSupportActionBar()

make sure that you have not used NoTitlebar Theme.

EDIT

use

ToolbarmToolbar= (Toolbar)findViewById(R.id.toolbar);
    mToolbar.setTitle(mTitle);

and add in your layout xml file :

create seprate file

<?xml version="1.0" encoding="utf-8"?><android.support.v7.widget.Toolbarxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="#E3493B"android:minHeight="?attr/actionBarSize"app:theme="@style/ThemeOverlay.AppCompat.ActionBar" >

include it in your xml layout file

<include layout="@layout/toolbar" />

Solution 2:

two things:

if you are using support framework the use "getSupportActionBar()" to get the actionbar. But i see you are using an activity here. Your activity should extend ActionbarActivity to use actionbar eith er directly or using a fragmentactivity.

without that you wont get an actionbar in support packages..

Solution 3:

The layout of the toolbar should be added to the activity layout

<include layout="@layout/toolbar" />

Post a Comment for "Null Pointer Exception At Action Bar"