NullPointerException with android.support.v7.widget.Toolbar
Set the id
attribute in the Toolbar
xml like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/app_bar"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" >
</android.support.v7.widget.Toolbar>
Then remove it from the include
block so it looks like this:
<include
layout="@layout/app_bar"/>
And to simplify further you could just remove the include
block completely and simply insert the Toolbar
directly into the xml where the include
was.
I solved the issue with the toolbar. I realized after hours of searching the web and trying different things, I realized that my code wasn't wrong, it was using layouts from the layout-21 not the layout folder since the emulation for Android 5.0. All modification I had made were in the layout folder. I made the changes to the xml files in the layout-21 folder and the problem was solved. Sorry for the wasted time and post.
<include
android:id="@+id/toolbar"
layout="@layout/tool_bar"/>
android.support.v7.widget.Toolbar.getTitle() on a null object reference happens due to title clashes between ids of and that of the id in toolbar.xml definition . To overcome this issue remove the id in as below and latest Lollipop material design shall work fine with toolbar
<include
layout="@layout/tool_bar"/>