android - Getting NullPointerException in searchview on action bar -
i working on application in setting searchview widget on action bar. getting null pointer exception . not getting idea why it's happening. followed many post none of them helping.
please guide me if making mistake... snippets are
searchactivity.java
public class searchactivity extends actionbaractivity{ @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_search); getactionbar().setdisplayhomeasupenabled(true); getactionbar().sethomebuttonenabled(true); handleintent(getintent()); } private void handleintent(intent intent) { if(intent.action_search.equals(intent.getaction())) { string query = intent.getstringextra(searchmanager.query); dosearch(query); }else if(intent.action_view.equals(intent.getaction())){ getplace(intent.getstringextra(searchmanager.extra_data_key)); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu items use in action bar menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.main, menu); menuitem searchitem = menu.finditem(r.id.action_search); // searchview , set searchable configuration searchmanager searchmanager = (searchmanager) getsystemservice(context.search_service); searchview searchview = (searchview) menu.finditem(r.id.action_search).getactionview(); searchview.setsearchableinfo(searchmanager.getsearchableinfo(getcomponentname())); // @ line getting null pointer exception searchview.seticonifiedbydefault(false); return super.oncreateoptionsmenu(menu); } }
xml/searchable.xml
<?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/app_name" android:hint="settings" android:searchsettingsdescription="settings" android:searchsuggestauthority="com.stata.mobile.android.dao.placeprovider" android:searchsuggestintentaction="android.intent.action.view" android:searchsuggestselection=" ?" android:searchsuggestthreshold="2" > </searchable>
androidmanifest.xml
<activity android:name=".ui.searchactivity" android:label="" android:launchmode="singletop"> <intent-filter> <action android:name="android.intent.action.search" /> </intent-filter> <!-- points searchable activity --> <meta-data android:name="android.app.default_searchable" android:value=".ui.searchactivity" /> <!-- points searchable meta data --> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/> </activity>
these codes using search thing. not able resolve null pointer exception getting @ line in oncreateoptions(menu)
searchview.setsearchableinfo(searchmanager.getsearchableinfo(getcomponentname()));
Comments
Post a Comment