gpt4 book ai didi

Android SearchView 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:51:15 25 4
gpt4 key购买 nike

我试图更新所有库,但我仍然遇到错误。我能够在模拟器上运行该应用程序,但是当我导出 APK 并在真实的 Android 设备上运行它时,该应用程序无法运行。

MinSdkVersion 为 8,targetSdkVersion 为 19。请帮忙!!!

菜单.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:example="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/action_showTC"
android:orderInCategory="100"
android:showAsAction="never"
android:title="Terms and Conditions"/>

<item android:id="@+id/action_search"
android:title="Search"
android:orderInCategory="100"
example:showAsAction="ifRoom|collapseActionView"
example:actionViewClass="android.support.v7.widget.SearchView"/>

</menu>

搜索 View

@Override
public boolean onOptionsItemSelected(MenuItem item){
if(item.getItemId() == R.id.action_showTC){
startActivity(new Intent(MainActivity.this, T_C.class));
return true;
}else{
return super.onOptionsItemSelected(item);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);

SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SupportMenuItem searchMenuItem = ((SupportMenuItem) menu.findItem(R.id.action_search));
SearchView searchView = (SearchView) searchMenuItem.getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

return super.onCreateOptionsMenu(menu);
}

list

    <activity android:name="com.agehk.queue.SearchResultsActivity"
android:parentActivityName="com.agehk.queue.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>

<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>

searchable.xml

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="Search Queue"
android:label="@string/app_name" />

错误

09-04 15:57:13.105: W/SupportMenuInflater(17184): Cannot instantiate class: android.support.v7.widget.SearchView
09-04 15:57:13.105: W/SupportMenuInflater(17184): java.lang.NoSuchMethodException: <init> [class android.content.Context]
09-04 15:57:13.105: W/SupportMenuInflater(17184): at java.lang.Class.getConstructorOrMethod(Class.java:423)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at java.lang.Class.getConstructor(Class.java:397)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.support.v7.internal.view.f.a(Unknown Source)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.support.v7.internal.view.f.a(Unknown Source)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.support.v7.internal.view.f.b(Unknown Source)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.support.v7.internal.view.d.a(Unknown Source)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.support.v7.internal.view.d.inflate(Unknown Source)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at com.agehk.queue.MainActivity.onCreateOptionsMenu(Unknown Source)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.app.Activity.onCreatePanelMenu(Activity.java:2577)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.support.v4.app.j.onCreatePanelMenu(Unknown Source)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.support.v7.a.g.a(Unknown Source)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.support.v7.a.n.a(Unknown Source)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.support.v7.a.g.onCreatePanelMenu(Unknown Source)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.support.v7.a.o.onCreatePanelMenu(Unknown Source)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:414)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:777)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:199)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:835)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.view.Choreographer.doCallbacks(Choreographer.java:626)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.view.Choreographer.doFrame(Choreographer.java:589)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:821)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.os.Handler.handleCallback(Handler.java:730)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.os.Handler.dispatchMessage(Handler.java:92)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.os.Looper.loop(Looper.java:150)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at android.app.ActivityThread.main(ActivityThread.java:5390)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at java.lang.reflect.Method.invokeNative(Native Method)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at java.lang.reflect.Method.invoke(Method.java:525)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-04 15:57:13.105: W/SupportMenuInflater(17184): at dalvik.system.NativeStart.main(Native Method)
09-04 15:57:13.105: D/AndroidRuntime(17184): Shutting down VM
09-04 15:57:13.105: W/dalvikvm(17184): threadid=1: thread exiting with uncaught exception (group=0x42f05500)
09-04 15:57:13.105: E/AndroidRuntime(17184): FATAL EXCEPTION: main
09-04 15:57:13.105: E/AndroidRuntime(17184): java.lang.NullPointerException
09-04 15:57:13.105: E/AndroidRuntime(17184): at com.agehk.queue.MainActivity.onCreateOptionsMenu(Unknown Source)
09-04 15:57:13.105: E/AndroidRuntime(17184): at android.app.Activity.onCreatePanelMenu(Activity.java:2577)
09-04 15:57:13.105: E/AndroidRuntime(17184): at android.support.v4.app.j.onCreatePanelMenu(Unknown Source)
09-04 15:57:13.105: E/AndroidRuntime(17184): at android.support.v7.a.g.a(Unknown Source)
09-04 15:57:13.105: E/AndroidRuntime(17184): at android.support.v7.a.n.a(Unknown Source)
09-04 15:57:13.105: E/AndroidRuntime(17184): at android.support.v7.a.g.onCreatePanelMenu(Unknown Source)
09-04 15:57:13.105: E/AndroidRuntime(17184): at android.support.v7.a.o.onCreatePanelMenu(Unknown Source)
09-04 15:57:13.105: E/AndroidRuntime(17184): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:414)
09-04 15:57:13.105: E/AndroidRuntime(17184): at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:777)
09-04 15:57:13.105: E/AndroidRuntime(17184): at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:199)
09-04 15:57:13.105: E/AndroidRuntime(17184): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:835)
09-04 15:57:13.105: E/AndroidRuntime(17184): at android.view.Choreographer.doCallbacks(Choreographer.java:626)
09-04 15:57:13.105: E/AndroidRuntime(17184): at android.view.Choreographer.doFrame(Choreographer.java:589)
09-04 15:57:13.105: E/AndroidRuntime(17184): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:821)
09-04 15:57:13.105: E/AndroidRuntime(17184): at android.os.Handler.handleCallback(Handler.java:730)
09-04 15:57:13.105: E/AndroidRuntime(17184): at android.os.Handler.dispatchMessage(Handler.java:92)
09-04 15:57:13.105: E/AndroidRuntime(17184): at android.os.Looper.loop(Looper.java:150)
09-04 15:57:13.105: E/AndroidRuntime(17184): at android.app.ActivityThread.main(ActivityThread.java:5390)
09-04 15:57:13.105: E/AndroidRuntime(17184): at java.lang.reflect.Method.invokeNative(Native Method)
09-04 15:57:13.105: E/AndroidRuntime(17184): at java.lang.reflect.Method.invoke(Method.java:525)
09-04 15:57:13.105: E/AndroidRuntime(17184): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-04 15:57:13.105: E/AndroidRuntime(17184): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-04 15:57:13.105: E/AndroidRuntime(17184): at dalvik.system.NativeStart.main(Native Method)
09-04 15:57:13.115: D/BatteryStatsImpl(445): noteStopWakeLocked com.google.android.gms isFromForeground = false
09-04 15:57:13.115: W/ActivityManager(445): Force finishing activity com.agehk.queue/.MainActivity

最佳答案

将以下代码添加到 proguard-rules.pro

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

关于Android SearchView 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25660793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com