i have a menu that contains just one item.
Button exit;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
MenuInflater blowUp = getMenuInflater();
blowUp.inflate(R.menu.exitmenu, menu);
return true;
}
exit=(Button)findViewById(R.id.bexitMenuExit);
if i add listener to exit button , i got excpetion (null pointer), i am sure that there is no syntax error, the button exit is comming from this menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/bexitMenuExit"
android:title="Exit"
android:icon="@android:drawable/ic_menu_close_clear_cancel"
></item>
</menu>
what am i doing wrong?
There is no need to initialize
Buttonand this doesn’t make sence for me.Just inflate your
Menuand just override onOptionsItemSelected method:Also, there is no need to use
OnClickListener, for this there isonOptionsItemSelectedmethod and you should use it.