I am trying to add a search string to an Actionbar and have detected a Nullpointer exception in getActionVeiw (). Prisoners help me solve this problem, I provided the necessary information.
My MainActivity extends AppCompatActivity and returns an error in this line of code
SearchView searchView = (SearchView)menu.findItem(R.id.action_search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
for the above searchview I am importing
import android.support.v7.widget.SearchView;
Menu file main.xml
<item
android:id="@+id/action_search"
android:orderInCategory="100"
android:title="@string/action_search"
app:showAsAction="always"
app:actionViewClass="android.support.v7.widget.SearchView" />
Gradle File -
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:+'
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
}
Akash source
share