java - getSupportActionBar().setDisplayHomeAsUpEnabled(true); throws NullPointerException -
first of all, know question has been asked before, i've spent hour looking through other solutions, - getactionbar() returns null , , none have worked pair of eyes might able something.
navigationdrawer class other classes inherit from:
public class navigationdrawer extends appcompatactivity { string[] mdrawertitles; drawerlayout mdrawerlayout; listview mdrawerlist; actionbardrawertoggle mdrawertoggle; string activitytitle; @override protected void oncreate(bundle savedinstancestate) { this.requestwindowfeature(window.feature_no_title); super.oncreate(savedinstancestate); setcontentview(r.layout.navigation_drawer_layout); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); mdrawertitles = getresources().getstringarray(r.array.drawer_array); mdrawerlayout = (drawerlayout) findviewbyid(r.id.drawer_layout); mdrawerlist = (listview) findviewbyid(r.id.left_drawer); activitytitle = gettitle().tostring(); getsupportactionbar().setdisplayhomeasupenabled(true); //here error thrown getsupportactionbar().sethomebuttonenabled(true); adddraweritems(); navdrawersetup(); } mainactiviy extends above:
public class mainactivity extends navigationdrawer { int[]images={r.drawable.user_manual,r.drawable.tips_tricks, r.drawable.troubleshooting}; integer printer; listview mylistview; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); layoutinflater inflater = (layoutinflater) this.getsystemservice(context.layout_inflater_service); view contentview = inflater.inflate(r.layout.activity_main, null, false); mdrawerlayout.addview(contentview, 0); } navigation drawer .xml
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <framelayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> <listview android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="#999" android:choicemode="singlechoice" android:divider="@android:color/transparent" android:dividerheight="0dp" /> </android.support.v4.widget.drawerlayout> styles.xml
<resources> <!-- base application theme. --> <style name="apptheme" parent="theme.appcompat.light.darkactionbar"> <!-- customize theme here. --> <item name="colorprimary">@color/colorprimary</item> <item name="colorprimarydark">@color/colorprimarydark</item> <item name="coloraccent">@color/coloraccent</item> </style> <style name="apptheme.noactionbar"> <item name="windowactionbar">false</item> <item name="windownotitle">true</item> </style> <style name="apptheme.appbaroverlay" parent="themeoverlay.appcompat.dark.actionbar" /> <style name="apptheme.popupoverlay" parent="themeoverlay.appcompat.light" /> </resources> activity_main
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.coordinatorlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitssystemwindows="true" tools:context="com.example.shelleyd.myapplication.mainactivity"> <android.support.design.widget.appbarlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/apptheme.appbaroverlay"> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" android:background="?attr/colorprimary" app:popuptheme="@style/apptheme.popupoverlay" /> </android.support.design.widget.appbarlayout> content_main
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/content_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="com.example.shelleyd.myapplication.mainactivity" tools:showin="@layout/activity_main"> <listview android:id="@+id/mylist" android:layout_width="match_parent" android:layout_height="0dp" android:layout_gravity="center_vertical" android:layout_weight="1" /> </linearlayout>
in navigationdrawer activity performing setcontentview(r.layout.navigation_drawer_layout), , in navigation_drawer_layout there no toolbar, leads exception.
Comments
Post a Comment