java - app crashes when it starts after defining onClick method of an Actionbar Icon -
i started programming android apps few days ago , have problem when want build app multiple activities:
basically want settings activity clicking on icon implemented in actionbar.
i set onclick attribute of icon startsettings
public void startsettings(view view) { intent intent = new intent(this, settingsactivity.class); startactivity(intent); }
in (menu) main.xml file ...
but when this, app crashes when want start it. weird thing is, when start method normal button in activity_main.xml file, works fine ... think problem in main.xml file. says in file method startsettings in 'mainactivity' has incorrect signature. , "checks if method specified in onclick xml attribute declared in related activity" don't know means ...:/
here error in console
e/androidruntime: fatal exception: main process: com.example.kevs272.testing, pid: 31225 theme: themes:{default=overlay:com.ashok.nougatcm, fontpkg:com.ashok.nougatcm, com.android.systemui=overlay:com.ashok.nougatcm, com.android.systemui.navbar=overlay:com.cyngn.hexo} android.view.inflateexception: couldn't resolve menu item onclick handler startsettings in class com.example.kevs272.testing.mainactivity @ android.support.v7.view.supportmenuinflater$inflatedonmenuitemclicklistener.<init>(supportmenuinflater.java:244) @ android.support.v7.view.supportmenuinflater$menustate.setitem(supportmenuinflater.java:444) @ android.support.v7.view.supportmenuinflater$menustate.additem(supportmenuinflater.java:479) @ android.support.v7.view.supportmenuinflater.parsemenu(supportmenuinflater.java:196) @ android.support.v7.view.supportmenuinflater.inflate(supportmenuinflater.java:118) @ com.example.kevs272.testing.mainactivity.oncreateoptionsmenu(mainactivity.java:23) @ android.app.activity.oncreatepanelmenu(activity.java:2852) @ android.support.v4.app.fragmentactivity.oncreatepanelmenu(fragmentactivity.java:360) @ android.support.v7.view.windowcallbackwrapper.oncreatepanelmenu(windowcallbackwrapper.java:88) @ android.support.v7.app.appcompatdelegateimplbase$appcompatwindowcallbackbase.oncreatepanelmenu(appcompatdelegateimplbase.java:331) @ android.support.v7.app.appcompatdelegateimplv9.preparepanel(appcompatdelegateimplv9.java:1353) @ android.support.v7.app.appcompatdelegateimplv9.doinvalidatepanelmenu(appcompatdelegateimplv9.java:1633) @ android.support.v7.app.appcompatdelegateimplv9$1.run(appcompatdelegateimplv9.java:132) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5461) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616)
and (menu) main.xml file
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/action_settings" android:title="settings" android:icon="@drawable/ic_settings_white_24dp" app:showasaction="always" android:onclick="startsettings" /> <item android:id="@+id/action_about" android:title="about" android:icon="@drawable/ic_info_outline_white_24dp" app:showasaction="always" /> </menu>
i recomend put function in on onmenuitemselected of activity this:
@override public boolean onmenuitemselected(int featureid, menuitem item) { switch (item.getitemid()) { case r.id.action_settings: startsettings(); return true; } return super.onmenuitemselected(featureid, item); }
and remove view param
Comments
Post a Comment