Failed to implement a search widget : <p>I'm trying to implement a search widget in my app . I found a useful tutorial from <a href="http://developer.android.com/intl/es/training/search/setup.html" rel="nofollow">here</a>.</p>

<p><a href="http://i.stack.imgur.com/T6bEp.png" rel="nofollow">My Activity A</a></p>

<p>But my app crashed.</p>

<p><strong>Activity A</strong></p>

<pre><code>     @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.create_menu, menu);
            // Associate searchable configuration with the SearchView
            SearchManager searchManager =
                    (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            SearchView searchView =
                    (SearchView) menu.findItem(R.id.search).getActionView();
            searchView.setSearchableInfo(
                    searchManager.getSearchableInfo(getComponentName()));
            return true;
        }

 @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        switch (item.getItemId()) {

            case R.id.add: // create new file
                View menuItemView = findViewById(R.id.add);
                PopupMenu po = new PopupMenu(HomePage.this, menuItemView); //for drop-down menu
                po.getMenuInflater().inflate(R.menu.popup_menu, po.getMenu());
                po.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    public boolean onMenuItemClick(MenuItem item) {
                        //  Toast.makeText(MainActivity.this, "You Clicked : " + item.getTitle(), Toast.LENGTH_SHORT).show();
                        if ("Create New File".equals(item.getTitle())) {
                            Intent intent = new Intent(HomePage.this, Information.class);  // go to Information class
                            startActivity(intent);

                        } else if ("Edit File".equals(item.getTitle())) {
                            Intent intent = new Intent(HomePage.this, Edit.class);
                            startActivity(intent);
                        }
                        return true;
                    }
                });
                po.show(); //showing popup menu

        }
        return super.onOptionsItemSelected(item);
    }
</code></pre>

<p><strong>searchable in xml folder</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;

&lt;searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/app_name"
    android:hint="Search by date" /&gt;
</code></pre>

<p><strong>create_menu</strong></p>

<pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"&gt;

    &lt;item android:id="@+id/search"
        android:title="Search by date"
        android:icon="@mipmap/search"
        app:showAsAction="collapseActionView|ifRoom"
        android:actionViewClass="android.widget.SearchView" /&gt;

    &lt;item
        android:icon="@mipmap/menu"
        android:id="@+id/add"
        android:orderInCategory="100"
        android:title="Main Menu"
        app:showAsAction="always" /&gt;

&lt;/menu&gt;
</code></pre>

<p>declare this in mainfest</p>

<pre><code>  &lt;meta-data android:name="android.app.searchable"
            android:resource="@xml/searchable" /&gt;
</code></pre>

<p><strong>Error LogCat</strong></p>

<pre><code>01-18 18:31:09.298    9215-9215/com.example.project.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.project.myapplication, PID: 9215
    java.lang.NullPointerException
            at com.example.project.myapplication.GUI.HomePage.onCreateOptionsMenu(HomePage.java:104)
            at android.app.Activity.onCreatePanelMenu(Activity.java:2646)
            at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:298)
            at android.support.v7.internal.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallback
</code></pre>

<p>This is the line where error pointed to   <code>searchView.setSearchableInfo(</code></p>
