title: java.lang.NullPointerException SearchView OnCreateOptionsMenu
body: <p>I am trying to make my app work for Gingerbread (API 10). My app crashes when I click on the menu with following error -</p>
  
  <pre><code>java.lang.NullPointerException
              at com.sample.appdemo.onCreateOptionsMenu(AppDemoListActivity.java:83)
  </code></pre>
  
  <p>My app worked fine with API 11 and higher in the past. Anyone please help?</p>
  
  <p>Here is what I have:</p>
  
  <p><strong>build.gradle</strong>:</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 21
      buildToolsVersion "21.1.2"
      defaultConfig {
          applicationId "com.sample.appdemo"
          minSdkVersion 8
          targetSdkVersion 19
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
          }
      }
      productFlavors {
      }
  }
  
  dependencies {
      compile project(':poi-3.10-FINAL-20140208')
      compile 'com.android.support:appcompat-v7:21.0.3'
  }
  </code></pre>
  
  <p><strong>AppDemoListActivity.java</strong></p>
  
  <pre><code>    package ...;
      import android.app.SearchManager;
      import android.support.v4.app.FragmentActivity;
      import android.support.v4.app.FragmentTransaction;
      import android.support.v4.view.MenuItemCompat;
      import android.support.v7.widget.SearchView;
      import ...;
  
      @Override
          public boolean onCreateOptionsMenu(Menu menu) {
              // Inflate the menu; this adds items to the action bar if it is present.
              MenuInflater inflater = getMenuInflater();
              inflater.inflate(R.menu.action_bar_search_optionsmenu, menu);
              SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  
          MenuItem searchItem = menu.findItem(R.id.action_search);
          SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
  
          ComponentName cn = new ComponentName(this, SearchActivity.class);
          searchView.setSearchableInfo(
                  searchManager.getSearchableInfo(cn)
          );
  
          return super.onCreateOptionsMenu(menu);
      }
  </code></pre>
  
  <p><strong>action_bar_search_menu:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &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/action_search"
          android:icon="@drawable/ic_action_search"
          android:title="@string/action_search"
          app:showAsAction="always"
          app:actionViewClass="android.support.v7.widget.SearchView"/&gt;
  &lt;/menu&gt;
  </code></pre>
  
  <p><strong>Update # 1:</strong></p>
  
  <p><strong>Manifest:</strong></p>
  
  <pre><code>&lt;activity
      android:name=".SearchActivity"
      android:label="@string/title_activity_search"
      android:parentActivityName=".AppDemoListActivity" &gt;
  
      &lt;!-- This intent-filter identifies this activity as "searchable" --&gt;
  
      &lt;intent-filter&gt;
          &lt;action android:name="android.intent.action.SEARCH" /&gt;
  
          &lt;category android:name="android.intent.category.DEFAULT" /&gt;
      &lt;/intent-filter&gt;
  
      &lt;!-- This metadata entry provides further configuration details for searches --&gt;
      &lt;!-- that are handled by this activity. --&gt;
  
      &lt;meta-data
          android:name="android.app.searchable"
          android:resource="@xml/searchable" /&gt;
  &lt;/activity&gt;
  </code></pre>