Rayne
Rayne

Reputation: 51

Error inflating class android.support.v7.widget.SearchView

I have tried to resolve this problem on my own but i can't get to a solution. There is a similar question on stackoverflow but none of the answers helped me ( Cannot instantiate class android.support.v7.widget.SearchView).

The search works perfect in another app. The problem appears when i try to implement it in another project.

This is the error that i get.

android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.v7.widget.SearchView

Here is my .xml. (in a LinearLayout)

<android.support.v7.widget.SearchView
    android:id="@+id/floating_search_view"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    app:iconifiedByDefault="false"
    app:actionViewClass="android.support.v7.widget.SearchView"
    />

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:drawSelectorOnTop="true"/>

In the following there is a part of my Manifest

<activity android:name=".robodex.Robodex"
        android:label="Robodex"
        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"/>
    </activity>

And here all the dependencies

android {
compileSdkVersion 24
buildToolsVersion "25.0.0"
defaultConfig {
    applicationId "it.uniroma1.android"
    minSdkVersion 21
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'
testCompile 'junit:junit:4.12'
compile files('libs/pocketsphinx-android-5prealpha-nolib.jar')
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.github.arimorty:floatingsearchview:2.0.3'
}

Upvotes: 5

Views: 5178

Answers (2)

Mohammed Faisal
Mohammed Faisal

Reputation: 53

Replace

android.support.v7.widget.SearchView

with

androidx.appcompat.widget.SearchView

It will work.

see: https://developer.android.com/jetpack/androidx/migrate/class-mappings

Upvotes: 5

Aishwarya Tiwari
Aishwarya Tiwari

Reputation: 625

Set your buildToolsVersion to 24.0.2 in your build.gradle and then see.

Upvotes: 0

Related Questions