gpt4 book ai didi

java - androidx.appcompat.widget.SearchView setSearchableInfo() 在某些设备上抛出 Resources$NotFoundException

转载 作者:行者123 更新时间:2023-12-05 07:17:42 26 4
gpt4 key购买 nike

我注意到报告日志中有几个异常,我不知道问题的原因是什么:

android.content.res.Resources$NotFoundException: 
at android.content.res.Resources.getText (Resources.java:363)
at android.content.Context.getText (Context.java:567)
at androidx.appcompat.widget.SearchView.getQueryHint (SearchView.java:622)
at androidx.appcompat.widget.SearchView.updateQueryHint (SearchView.java:1102)
at androidx.appcompat.widget.SearchView.setSearchableInfo (SearchView.java:409)
at com.myApp.MainActivity.onCreateOptionsMenu (MainActivity.java:161)
at android.app.Activity.onCreatePanelMenu (Activity.java:3575)
at androidx.fragment.app.FragmentActivity.onCreatePanelMenu (FragmentActivity.java:325)
at androidx.appcompat.view.WindowCallbackWrapper.onCreatePanelMenu (WindowCallbackWrapper.java:94)
at androidx.appcompat.app.AppCompatDelegateImpl$AppCompatWindowCallback.onCreatePanelMenu (AppCompatDelegateImpl.java:2830)
at androidx.appcompat.view.WindowCallbackWrapper.onCreatePanelMenu (WindowCallbackWrapper.java:94)
at androidx.appcompat.app.ToolbarActionBar.populateOptionsMenu (ToolbarActionBar.java:455)
at androidx.appcompat.app.ToolbarActionBar$1.run (ToolbarActionBar.java:56)
at android.view.Choreographer$CallbackRecord.run (Choreographer.java:949)
at android.view.Choreographer.doCallbacks (Choreographer.java:761)
at android.view.Choreographer.doFrame (Choreographer.java:693)
at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:935)
at android.os.Handler.handleCallback (Handler.java:873)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:214)
at android.app.ActivityThread.main (ActivityThread.java:7094)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:975)

MainActivity.java

public class MainActivity extends AppCompatActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_activity_actions, menu);
mainMenu = menu;
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
MenuItem searchItem = menu.findItem(R.id.action_search);
searchView = (SearchView) searchItem.getActionView();
if(searchManager != null) {
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
}
return super.onCreateOptionsMenu(menu);
}
}

R.menu.main_activity_actions.xml 看起来像

<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_search"
android:title="@string/search"
android:icon="@drawable/ic_search_white"
android:orderInCategory="1"
app:showAsAction="ifRoom|collapseActionView"
app:actionViewClass="androidx.appcompat.widget.SearchView"/>
</menu>

抛出异常的设备是Samsung Galaxy J6+ (Android 9), Xiaomi Redmi 6A (Android 9)

我不知道哪个解决方案是正确的,因为我试图重复这个问题,但无法做到。很少抛出此异常。迁移到AndroidX后开始

最佳答案

    <item
android:id="@+id/search_menu"
android:icon="@drawable/ic_action_search"
android:orderInCategory="101"
android:title="@string/search_text"
app:showAsAction="ifRoom"
app:actionViewClass="androidx.appcompat.widget.SearchView"/>

androidx app:actionViewClass="androidx.appcompat.widget.SearchView"

关于java - androidx.appcompat.widget.SearchView setSearchableInfo() 在某些设备上抛出 Resources$NotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58657982/

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