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:

  • Meilleures pratiques pour exposer plusieurs tables à l'aide de fournisseurs de contenu dans Android
  • Ouvrir un document PDF protégé par mot de passe et rendre dans Android une nouvelle classe "PdfRenderer"?
  • TileProvider utilisant des carreaux locaux
  • Comment utiliser sa propre vue dans la mise en page?
  • Android ICS: erreur JNI tente d'utiliser la référence local 0x1
  • Ce SDK d'Android requiert Android Developer Toolkit version 14.0.0 ou plus haut. ... Veuillez mettre à jour ADT vers la dernière version
  • <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 

  • Android MVP open Activity de Presenter, anti-pattern?
  • Garniture supérieure / inférieure pour Spinner
  • Comment dessiner un cercle avec une animation dans Android avec une taille de cercle basée sur une valeur
  • Argument de passage à DialogFragment
  • Exemple de l'application android.util.Pair
  • (Comment) Un périphérique virtuel Android peut-il utiliser l'Internet local de l'ordinateur?
  • 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.