Impossible d'instancier la classe android.support.v7.widget.SearchView

S'il vous plaît, quelqu'un m'aide! J'essaie d'ajouter la vue de recherche appcompat à mon projet. Sans succès. Lorsque je change android.support.v7.widget.SearchView to SearchView (API> 10), tout va bien.

Ceci mon menu rés:

  • Différence et utilisations de onCreate (), onCreateView () et onActivityCreated () en fragments
  • Comment puis-je assigner une ID à une vue par programme?
  • RxJava2 dans le rappel de OnLoadFinished de CursorLoader
  • Le bluetooth Android ne peut pas se connecter
  • Android: Comment puis-je empêcher le clavier doux de pousser ma vue?
  • Quelle est la couleur par défaut pour le texte dans la visualisation de texte?
  • <item android:id="@+id/action_search" android:title="@string/search_view_title" android:icon="@drawable/action_search" sabd:showAsAction="always|collapseActionView" sabd:actionViewClass="android.support.v7.widget.SearchView" /> 

    Voici comment j'essaie d'utiliser SeachView:

      @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.teach, menu); mSearchItem = menu.findItem(R.id.action_search); mSearchItem.setVisible(true); mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchItem); mSearchView.setQueryHint(getString(R.string.search_view_hint)); mSearchView.setOnQueryTextListener(this); } 

    Ce fichier manifeste:

     <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ru.rgups.time" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17" /> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/Theme.Base.AppCompat.Light" android:name="RTApplication"> <activity android:name="ru.rgups.time.MainActivity" android:configChanges="orientation|keyboardHidden" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".fragments.WelcomeActivity"></activity> <service android:name=".spice.SampleSpiceService"></service> <activity android:name=".activities.AuthActivity"></activity> <activity android:name=".activities.HomeWorkActivity" android:uiOptions="splitActionBarWhenNarrow"> </activity> <receiver android:name="ru.rgups.time.receiver.HomeWorkNotificationReceiver"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </receiver> </application> </manifest> 

    Et ce que je vois dans les journaux:

      03-22 21:46:58.583: W/SupportMenuInflater(28798): Cannot instantiate class: android.support.v7.widget.SearchView 03-22 21:46:58.583: W/SupportMenuInflater(28798): java.lang.reflect.InvocationTargetException 03-22 21:46:58.583: W/SupportMenuInflater(28798): at java.lang.reflect.Constructor.constructNative(Native Method) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.support.v7.internal.view.SupportMenuInflater$MenuState.newInstance(SupportMenuInflater.java:482) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.support.v7.internal.view.SupportMenuInflater$MenuState.setItem(SupportMenuInflater.java:441) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.support.v7.internal.view.SupportMenuInflater$MenuState.addItem(SupportMenuInflater.java:462) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.support.v7.internal.view.SupportMenuInflater.parseMenu(SupportMenuInflater.java:196) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.support.v7.internal.view.SupportMenuInflater.inflate(SupportMenuInflater.java:118) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at ru.rgups.time.fragments.TeachersListFragment.onCreateOptionsMenu(TeachersListFragment.java:109) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.support.v4.app.Fragment.performCreateOptionsMenu(Fragment.java:1582) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.support.v4.app.FragmentManagerImpl.dispatchCreateOptionsMenu(FragmentManager.java:1956) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:225) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:232) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.support.v7.app.ActionBarActivityDelegateICS.onCreatePanelMenu(ActionBarActivityDelegateICS.java:147) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.support.v7.app.ActionBarActivity.onCreatePanelMenu(ActionBarActivity.java:199) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onCreatePanelMenu(ActionBarActivityDelegateICS.java:285) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:436) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:800) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:221) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.view.Choreographer.doCallbacks(Choreographer.java:574) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.view.Choreographer.doFrame(Choreographer.java:543) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.os.Handler.handleCallback(Handler.java:733) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.os.Handler.dispatchMessage(Handler.java:95) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.os.Looper.loop(Looper.java:136) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.app.ActivityThread.main(ActivityThread.java:5017) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at java.lang.reflect.Method.invokeNative(Native Method) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at java.lang.reflect.Method.invoke(Method.java:515) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at dalvik.system.NativeStart.main(Native Method) 03-22 21:46:58.583: W/SupportMenuInflater(28798): Caused by: android.view.InflateException: Binary XML file line #41: Error inflating class <unknown> 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.view.LayoutInflater.createView(LayoutInflater.java:620) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.support.v7.widget.SearchView.<init>(SearchView.java:262) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.support.v7.widget.SearchView.<init>(SearchView.java:254) 03-22 21:46:58.583: W/SupportMenuInflater(28798): ... 31 more 03-22 21:46:58.583: W/SupportMenuInflater(28798): Caused by: java.lang.reflect.InvocationTargetException 03-22 21:46:58.583: W/SupportMenuInflater(28798): at java.lang.reflect.Constructor.constructNative(Native Method) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.view.LayoutInflater.createView(LayoutInflater.java:594) 03-22 21:46:58.583: W/SupportMenuInflater(28798): ... 39 more 03-22 21:46:58.583: W/SupportMenuInflater(28798): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f010069 a=-1} 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.content.res.Resources.loadDrawable(Resources.java:2068) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.content.res.TypedArray.getDrawable(TypedArray.java:602) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.widget.ImageView.<init>(ImageView.java:129) 03-22 21:46:58.583: W/SupportMenuInflater(28798): at android.widget.ImageView.<init>(ImageView.java:119) 03-22 21:46:58.583: W/SupportMenuInflater(28798): ... 42 more 

  • Crash de la caméra de manière inattendue dans le nexus de galaxy
  • Comment changer le titre de l'activité dans Android?
  • Génération d'une clé de hachage pour une application utilisant Facebook sdk
  • Android: LocationManager vs Google Play Services
  • Régler l'alarme depuis Android 4.4 Kitkat
  • Android: redémarrez l'application après la mise à jour - ACTION_PACKAGE_REPLACED
  • 3 Solutions collect form web for “Impossible d'instancier la classe android.support.v7.widget.SearchView”

    J'ai eu un semblable probablement qui est apparu sur mon version, mais pas mes builds de débogage lors de la connexion à la bibliothèque de support v21. Il s'est avéré être un problème d'obfuscation, et l'ajout de cette ligne à mon fichier proguard-rules.txt corrigé:

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

    J'ai eu le même problème lorsque j'utilise Android Studio et Gradle pour créer mon projet. Je voudrais ajouter un SearchView de v7 compat.

    La solution consiste à changer la version du plugin gradle de 0.9.1 ou de autres à 0.9.0. C'est une façon temporaire que j'ai trouvée. C'est peut-être un bug de gradle plugin. J'espère que cela pourra aider.

      dependencies { classpath "com.android.tools.build:gradle:0.9.0" } 

    Le problème était dans la mauvaise bibliothèque de support v7. Après avoir mis à jour tout bien.

    coAndroid est un fan Android de Google, tout sur les téléphones Android, Android Wear, Android Dev et Android Games Apps.