Android - NullPointerException on SearchView in Action Bar
Try to replace the failing line with:
mSearchMenuItem = menu.findItem(R.id.action_search);
mSearchView = (EnglishVerbSearchView) MenuItemCompat.getActionView(mSearchMenuItem);
Where R.id.action_search is the id of your search item in the menu.
EDIT
Your manifest should look like that:
<activity
android:name="com.bronzelabs.twc.activities.WorkflowListActivity"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.SearchResultActivity"
android:theme="@style/Theme.AppCompat.Light"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable"
android:value=".activities.SearchResultActivity" />
</activity>
The way you call setSearchableInfo
is:
mSearchView.setSearchableInfo(searchManager.getSearchableInfo(
new ComponentName(getApplicationContext(), SearchResultActivity.class)));
EDIT 2
Make sure your menu xml file is like that (pay attention to those 2 attributes with yourapp
namespace - this is needed when you use the compat library):
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_search"
android:title="@string/action_search"
android:icon="@drawable/action_search"
yourapp:showAsAction="always|collapseActionView"
yourapp:actionViewClass="android.support.v7.widget.SearchView" />
</menu>
Android - Null pointer exception in searchview
You should look for the search view in your fragment's view, not in your activity's view.
Change
searchView1 = (SearchView) getActivity().findViewById(R.id.searchView1);
to
searchView1 = (SearchView) rootView.findViewById(R.id.searchView1);
Android Action Bar SearchView NullPointerException adjustDropDownSizeAndPosition
This problem is caused by styles being applied to the EditText
in the action bar SearchView
.
You can fix this by removing any style you have applied to EditText
such as:
res/values/styles.xml
<item name="android:editTextStyle">@style/editor</item>
Then go to each EditText
view in your layout XML and apply the style directly:
<EditText style="@style/editor" />
Related Topics
How to Install Android Sdk Build Tools on the Command Line
Android Image View Pinch Zooming
Android Dependency Has Different Version for the Compile and Runtime
Fade in Fade Out Android Animation in Java
Any Way to Run Shell Commands on Android Programmatically
Get the Uri of an Image Stored in Drawable
How to Generate a Thumbnail from a Video Url in Android
What's Dp (Density Independent Pixels) Units with CSS
How to Get Text on an Actionbar Icon
Panic: Broken Avd System Path. Check Your Android_Sdk_Root Value
Adb Root Is Not Working on Emulator (Cannot Run as Root in Production Builds)
Was Preferencefragment Intentionally Excluded from the Compatibility Package
How to Rename the Android Package Name