Monday, 7 October 2019

searchview issue in a specific device androidx

I have moved my code to androidx it is working fine in other devices but I'm getting

java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.appcompat.widget.SearchView.setSearchableInfo(android.app.SearchableInfo)' on a null object reference at packagename.FileName.onCreateOptionsMenu (FileName.java:43)in VIVO Devices

following is my menu code

   <item
    android:id="@+id/action_search"
    android:icon="@android:drawable/ic_search_category_default"
    android:orderInCategory="100"
    android:title="@string/w_search"
    app:showAsAction="always"
    app:actionViewClass="androidx.appcompat.widget.SearchView" />

I am not able to figure out for what reasons this is happening.

EDIT:

for context if it helps, I was having similar issue in com.google.android.material.textfield.TextInputLayout but after adding app:passwordToggleDrawable="@null" it was resolved

EDIT 2:

SearchView code

    getMenuInflater().inflate(R.menu.menu_search, menu);

    // Associate searchable configuration with the SearchView
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) menu.findItem(R.id.action_search)
            .getActionView();
    searchView.setSearchableInfo(searchManager
            .getSearchableInfo(getComponentName()));
    searchView.setMaxWidth(Integer.MAX_VALUE);
    searchView.setQueryHint(getResources().getString(R.string.w_hint_search));

    SearchView.SearchAutoComplete searchAutoComplete = searchView.findViewById(R.id.search_src_text);
    searchAutoComplete.setHintTextColor(Color.parseColor("#5FFFFFFF"));
    searchAutoComplete.setTextColor(Color.WHITE);


from searchview issue in a specific device androidx

No comments:

Post a Comment