Null Pointer exception when using SearchView with AppCompat

前端 未结 2 1294
野的像风
野的像风 2021-01-04 06:19

Today I have spent the time to migrate to the AppCompat library. I have setup everything successfully except my SearchView.

Before, it functioned properly, but now I

2条回答
  •  清歌不尽
    2021-01-04 07:00

    I had to do 3 things for this to work:

    1. I went to my proguard-android.txt file found on my machine at Android/sdk/tools/proguard and I pasted the following at the bottom of the file:

    -keep class android.support.v7.widget.SearchView { *; }

    (then I saved the file)

    1. In my action_menu.xml file in my project found at res/menu I originally had this android:actionViewClass="android.support.v7.widget.SearchView"

    but I changed it to this

    app:actionViewClass="android.support.v7.widget.SearchView" (the only difference being the word android and app)

    So it currently looks like this:

    
    
    1. Then I cleaned my project.

    I ran it and it finally worked! No more null pointer exception! :)

提交回复
热议问题