Monday, 1 April 2019

SearchView crashes with inflation error (androidx) - resource not found exception

I have a SearchView in one of my layouts and get appended crash on some devices. The problem is that the abc_textfield_search_material resource is not found. But I'm not using this resource directly, as my xml layout simply looks like following:

<androidx.appcompat.widget.SearchView
        android:id="@+id/svSearch"
        android:visibility="gone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:iconifiedByDefault="false"
        android:queryHint="@string/filter"
        app:iconifiedByDefault="false"
        android:paddingBottom="4dp"
        app:queryHint="@string/filter" />

Any ideas how to solve this? This crash happens on rare devices only (less than 1%), most devices simply work. I'm already thinking about changing this to a TextView with a compound drawable instead but maybe there's a better solution than just avoiding to use a SearchView

Stacktrace

java.lang.RuntimeException: Unable to pause activity {com.my.app/com.my.app.MainActivity}: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class androidx.appcompat.widget.SearchView
    at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:4071)
    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:4026)
    at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3978)
    at android.app.servertransaction.PauseActivityItem.execute(PauseActivityItem.java:45)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1818)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6744)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:495)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class androidx.appcompat.widget.SearchView
Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class androidx.appcompat.widget.SearchView
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance0(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
    at android.view.LayoutInflater.createView(LayoutInflater.java:647)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    ...
Caused by: android.content.res.Resources$NotFoundException: Drawable com.my.app:drawable/abc_textfield_search_material with resource ID #0x7f080058
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_textfield_search_material.xml from drawable resource ID #0x7f080058
    at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:847)
    at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:631)
    at android.content.res.Resources.getDrawableForDensity(Resources.java:888)
    at android.content.res.Resources.getDrawable(Resources.java:827)
    at android.content.Context.getDrawable(Context.java:635)
    at androidx.core.content.ContextCompat.a(ContextCompat.java:463)
    at androidx.appcompat.widget.AppCompatDrawableManager.a(AppCompatDrawableManager.java:203)
    at androidx.appcompat.widget.AppCompatDrawableManager.a(AppCompatDrawableManager.java:191)
    at androidx.appcompat.content.res.AppCompatResources.b(AppCompatResources.java:102)
    at androidx.appcompat.widget.TintTypedArray.a(TintTypedArray.java:76)
    at androidx.appcompat.widget.SearchView.<init>(SearchView.java:298)
    at androidx.appcompat.widget.SearchView.<init>(SearchView.java:270)
    at java.lang.reflect.Constructor.newInstance0(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
    at android.view.LayoutInflater.createView(LayoutInflater.java:647)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    ...

Theme

I'm using an android x theme in my app - Theme.MaterialComponents.NoActionBar.Bridge



from SearchView crashes with inflation error (androidx) - resource not found exception

No comments:

Post a Comment