Calling Search Dialog from OnItemClickListener
<p>I'm having a weird problem.  I'm trying implement a search in my app.  If I press the search button or if I call onSearchRequested() from the onStart() function the search screen shows up.  But If I call onSearchReqeusted() from a OnItemClickListener's onItemClick function, I get a NullPointerException.  I have also tried to get an instance of the search manager, and call the startSearch function directly but it also fails.  </p>

<p>I think this person <a href="http://stackoverflow.com/questions/4465529/how-do-i-invoke-the-search-dialog-using-onsearchrequested">How do I invoke the search dialog using onSearchRequested()</a> is having the same problem and it wasn't answered, but I'm not sure.</p>

<p>Here is my OnStart Method:</p>

<pre><code>@Override
    protected void onStart() {  
        super.onStart();
        this.setContentView(R.layout.mainactivity);
        ListView lv = (ListView)this.findViewById(R.id.MainActivityList);

        lv.setAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, actions));
        onSearchRequested();   //This works...
        lv.setOnItemClickListener(new OnItemClickListener(){

            public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {

                Intent i = null;
                Context c = MainActivity.this;
                //position is the index of actions above.
                switch(position)
                {
                case 0:
                    i = new Intent(c,MainCategoryActivity.class);
                    break;
                case 1:
                    //SearchManager sm = (SearchManager) MainActivity.this.getSystemService(Context.SEARCH_SERVICE);
                    //sm.startSearch(null, false, new ComponentName(MainActivity.this, MainActivity.class) , null, false);


                    onSearchRequested();   //NullPointerException
                    break;
                case 2:
                    i = new Intent(c,SelectCityActivity.class);
                    break;
                case 3:
                    i = new Intent(c,SavedSearchesActivity.class);
                    break;              
                }

                c.startActivity(i);


            }});

    }
</code></pre>

<p>Here are the exception logs:</p>

<pre><code>      06-28 16:09:22.368: E/AndroidRuntime(1702): FATAL EXCEPTION: main
      06-28 16:09:22.368: E/AndroidRuntime(1702): java.lang.NullPointerException
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at android.app.Activity.startActivityForResult(Activity.java:3190)
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at android.app.Activity.startActivity(Activity.java:3297)
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at com.TheGreensheet.GreensheetReader.MainActivity$1.onItemClick(MainActivity.java:47)
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at android.widget.AdapterView.performItemClick(AdapterView.java:292)
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at android.widget.AbsListView$1.run(AbsListView.java:3168)
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at android.os.Handler.handleCallback(Handler.java:605)
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at android.os.Handler.dispatchMessage(Handler.java:92)
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at android.os.Looper.loop(Looper.java:137)
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at android.app.ActivityThread.main(ActivityThread.java:4424)
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at java.lang.reflect.Method.invokeNative(Native Method)
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at java.lang.reflect.Method.invoke(Method.java:511)
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
      06-28 16:09:22.368: E/AndroidRuntime(1702):   at dalvik.system.NativeStart.main(Native Method)
</code></pre>
