java - I'm getting the following runtime error. Please help me figure out why -


i'm developing app material design.

after running below code & tapping on 'about' option menu, app crashing & i'm running following exceptions:

java.lang.runtimeexception: unable start activity componentinfo{com.abc.xyz/com.abc.xyz.aboutactivity}:
java.lang.nullpointerexception: attempt invoke virtual method 'void android.support.v7.app.actionbar.setdisplayhomeasupenabled(boolean)' on null object reference`

here's aboutactivity.java file's code:

public class aboutactivity extends appcompatactivity {      public toolbar toolbar;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_about);          spannablestring s = new spannablestring("about");         s.setspan(new typefacespan(this, "pacifico.ttf"), 0, s.length(),                 spannable.span_exclusive_exclusive);          getsupportactionbar().setdisplayhomeasupenabled(true);         getsupportactionbar().settitle(s);     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.menu_about, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();          //noinspection simplifiableifstatement         if (id == r.id.action_settings) {             return true;         }          return super.onoptionsitemselected(item);     } } 

as i'm new material design, don't know here.

have created toolbar widget in "activity_about.xml"?

<android.support.v7.widget.toolbar   android:id=”@+id/my_awesome_toolbar”   android:layout_height=”wrap_content”   android:layout_width=”match_parent”   android:minheight=”?attr/actionbarsize”   android:background=”?attr/colorprimary” /> 

also have toolbar toolbar; variable redundant. remove if not using it.

try: remove call getsupportactionbar.

toolbar toolbar = (toolbar) findviewbyid(r.id.my_awesome_toolbar); setsupportactionbar(toolbar); toolbar.sethomebuttonenabled(true); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -