Results 1 to 5 of 5
  1. #1
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    7

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

    Here is an SSCCE. I was initially using 23.1.1 version of appcompat_v7 support library, but then I also tried 23.0.1 and 21.0.3 versions as well. I am running it on a Genymotion emulator with version 23 of Android SDK.

    The exact error from the logcat is given at the end.

    activity_main.xml:
    Java Code:
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <android.support.v7.widget.SearchView
            android:id="@+id/mainActivity_searchView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    
        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
    </LinearLayout>
    MainActivity.java:

    Java Code:
    public class MainActivity extends Activity {
        SearchView searchView;
        TextView textView;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.activity_main);
            searchView = (SearchView) findViewById(R.id.mainActivity_searchView);
            textView = (TextView) findViewById(R.id.textView);
    
            searchView.setSearchableInfo(((SearchManager) getSystemService(SEARCH_SERVICE)).getSearchableInfo(getComponentName())); 
    
            searchView.setIconifiedByDefault(false); 
    
            handleIntent(getIntent());
        }
    
        @Override
        protected void onNewIntent(Intent intent) {
            setIntent(intent);
            handleIntent(intent);
        }
    
        private void handleIntent(Intent intent) {
            if (intent.getAction().equals(Intent.ACTION_SEARCH)) {
                String searchQuery = intent.getStringExtra(SearchManager.QUERY);
                performSearch(searchQuery);
            }
        }
    
        private void performSearch(String searchQuery) {
            textView.setText(searchQuery);
        }
    }
    searchable.xml:
    Java Code:
    <?xml version="1.0" encoding="utf-8"?>
    <searchable xmlns:android="http://schemas.android.com/apk/res/android" 
        android:label="@string/app_name"
        android:hint="@+id/search_view_hint" ></searchable>
    Manifest:
    Java Code:
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="tests.test"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="23" />
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
    
            <activity
                android:name="tests.test.module_s.ui.MainActivity"
                android:label="@string/app_name"
                android:launchMode="singleTop" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
                <intent-filter>
                    <action android:name="android.intent.action.SEARCH" />
                </intent-filter>
                <meta-data android:name="android.app.searchable"
                    android:resource="@xml/searchable" />
            </activity>
    
            <meta-data android:name="android.app.default_Searchable"
                android:value=".MainActivity" />
        </application>
    
    </manifest>
    LOGCAT:
    Java Code:
    java.lang.RuntimeException: Unable to start activity ComponentInfo{tests.test/tests.test.module_s.ui.MainActivity}: android.view.InflateException: Binary XML file line #6: Binary XML file line #6: Error inflating class android.support.v7.widget.SearchView

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Error inflating class android.support.v7.widget.SearchView

    Is there more in the logcat that describes the problem?

    The posted code does not show what package it is in.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    7

    Default Re: Error inflating class android.support.v7.widget.SearchView

    Is there more in the logcat that describes the problem?
    Yeah following is the complete error description from the logcat. I am also attaching the Eclipse project, in case you want to run it..

    Java Code:
    02-16 23:28:11.003: E/AndroidRuntime(1810): FATAL EXCEPTION: main
    02-16 23:28:11.003: E/AndroidRuntime(1810): Process: tests.test, PID: 1810
    02-16 23:28:11.003: E/AndroidRuntime(1810): java.lang.RuntimeException: Unable to start activity ComponentInfo{tests.test/tests.test.module_s.ui.MainActivity}: android.view.InflateException: Binary XML file line #6: Binary XML file line #6: Error inflating class android.support.v7.widget.SearchView
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.app.ActivityThread.-wrap11(ActivityThread.java)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.os.Handler.dispatchMessage(Handler.java:102)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.os.Looper.loop(Looper.java:148)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.app.ActivityThread.main(ActivityThread.java:5417)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at java.lang.reflect.Method.invoke(Native Method)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    02-16 23:28:11.003: E/AndroidRuntime(1810): Caused by: android.view.InflateException: Binary XML file line #6: Binary XML file line #6: Error inflating class android.support.v7.widget.SearchView
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.app.Activity.setContentView(Activity.java:2166)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at tests.test.module_s.ui.MainActivity.onCreate(MainActivity.java:19)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.app.Activity.performCreate(Activity.java:6237)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	... 9 more
    02-16 23:28:11.003: E/AndroidRuntime(1810): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class android.support.v7.widget.SearchView
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.createView(LayoutInflater.java:645)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	... 17 more
    02-16 23:28:11.003: E/AndroidRuntime(1810): Caused by: java.lang.reflect.InvocationTargetException
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at java.lang.reflect.Constructor.newInstance(Native Method)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.createView(LayoutInflater.java:619)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	... 22 more
    02-16 23:28:11.003: E/AndroidRuntime(1810): Caused by: android.view.InflateException: Binary XML file line #97: Binary XML file line #97: Error inflating class <unknown>
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.support.v7.widget.SearchView.<init>(SearchView.java:286)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.support.v7.widget.SearchView.<init>(SearchView.java:272)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	... 24 more
    02-16 23:28:11.003: E/AndroidRuntime(1810): Caused by: android.view.InflateException: Binary XML file line #97: Error inflating class <unknown>
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.createView(LayoutInflater.java:645)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	... 27 more
    02-16 23:28:11.003: E/AndroidRuntime(1810): Caused by: java.lang.reflect.InvocationTargetException
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at java.lang.reflect.Constructor.newInstance(Native Method)
    02-16 23:28:11.003: E/AndroidRuntime(1810): 	at android.view.LayoutInflater.createView(Layo
    Attached Files Attached Files

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: Error inflating class android.support.v7.widget.SearchView

    You'e developing against 23, so you shouldn't be using the v7 classes anyway.
    They're intended for code designed to run on pre-11 systems (pre the changes brought in for Android 3.0).

    According to the API docs:
    "
    This class is included in the support library for compatibility with API level 7 and higher. If you're developing your app for API level 11 and higher only, you should instead use the framework SearchView class.
    "
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    7

    Default Re: Error inflating class android.support.v7.widget.SearchView

    You'e developing against 23, so you shouldn't be using the v7 classes anyway.
    From my manifest file,

    Java Code:
    <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="23" />
    So you see, I want it to run on devices running SDK version 8 through to those running version 23. I want to provide Appcompat SearchView for those running pre-lollipop.

    Is there still a problem in this example app?
    Last edited by Zarah; 02-21-2016 at 12:28 AM.

Similar Threads

  1. Replies: 0
    Last Post: 08-10-2015, 08:36 AM
  2. Replies: 0
    Last Post: 08-07-2015, 12:19 PM
  3. "import android.widget.Button;" What does that mean?
    By java java in forum New To Java
    Replies: 2
    Last Post: 03-02-2015, 06:34 PM
  4. Replies: 0
    Last Post: 09-25-2014, 08:43 AM
  5. Multiple versions of android-support-v4
    By kjkrum in forum Android
    Replies: 1
    Last Post: 03-11-2014, 10:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •