OpenOptionMenu from ImageButton gives null pointer exception
<p>I am trying to invoke optionMenu from ImageButton in onClick listener but getting following exception.</p>

<pre><code>07-19 01:08:09.693: E/AndroidRuntime(15133): java.lang.NullPointerException: Attempt to invoke interface method 'android.view.MenuItem android.view.Menu.getItem(int)' on a null object reference


    public class myApp extends Activity  implements  OnClickListener {

      @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

       }

    /** Called when the activity is first created. */
    @Override
    public void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);

        setContentView(R.layout.main);

        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);

        menu_icon  = (ImageView) findViewById(R.id.icon);
        infoBtn = (ImageButton) findViewById(R.id.pfkey_button);
        menu_icon.setImageResource(R.drawable.info_icon);

        menu_icon.setOnClickListener(this);
        infoBtn.setOnClickListener(this);

        //Create Terminal View
        terminalView = (TerminalView)findViewById(R.id.terminalView);//new TerminalView(this);     

        registerForContextMenu(terminalView);

    }


    public void onClick(View v) {


            KeyEvent event = null;

            if (v == infoBtn) {
                openOptionsMenu();
            }

            if (v == menu_icon) {
                openOptionsMenu();
            }

        }

}
</code></pre>

<p>I also tried with `infoBtn = (ImageButton)myApp.this.findViewById(R.id.pfkey_button);  but not working</p>