gpt4 book ai didi

Android 支持库 v7 Searchview 错误

转载 作者:太空狗 更新时间:2023-10-29 15:04:50 26 4
gpt4 key购买 nike

我的应用程序使用带 fragment 的 ActionBar 选项卡,作为第一步,我只使用了 v4 库。但现在我也实现了 v7 appcompat。在 API>11 的设备上它工作正常,因为我只使用 ActivityCompat.invalidateOptionsMenu(this.getActivity());但是对于具有 API<11 的设备,应用程序似乎每次都崩溃 getActivity().supportInvalidateOptionsMenu(); 被调用时说存在膨胀异常:android.view.InflateException:二进制 XML 文件第 85 行:错误膨胀类在 dalvikvm 中:找不到类“android.support.v7.widget.SearchView$5”,从方法 android.support.v7.widget.SearchView.addOnLayoutChangeListenerToDropDownAnchorSDK11 中引用

过去 3 周我在网上搜索,这里是我设法找到的东西:

首先是this .

这还不足以解决问题,但后来我还发现了 this .

现在我使用 eclipse,但在从上面的链接阅读 Issue 67388 后,我下载了 android studio 0.5.4 以查看它是否也适用于我。我需要将 Build gradle 设置为 0.9.0 版,将 android.support.v4/android.support.v7 设置为 19.0.1 版,因为 19.1.0应用程序仍然崩溃。

现在该应用程序在设备 API>11 上运行良好,如 android 2.2.3 2.3 等,但如果您从 NullPointerException 旋转设备将崩溃

根据logcat,导致异常的代码是:

mSearchView = new MySearchView(getActivity());

在 4.4 上工作正常,但是当我在 android 3.0 或 4.0/4.1/4.2.1 等上运行应用程序时,应用程序再次崩溃并显示 android.view.InflateException: Binary XML file line #85: Error inflating class 当我旋转设备时会崩溃。

我能解决这个问题吗?如何解决?我真的被困住了,不知道该怎么办了提前致谢。

这是完整的日志猫:

膨胀异常

E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #85: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:513)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.support.v7.widget.SearchView.<init>(SearchView.java:262)
at android.support.v7.widget.SearchView.<init>(SearchView.java:254)
at com.samer.deutschwordbookapp.Words$MySearchView.<init>(Words.java:459)
at com.samer.deutschwordbookapp.Words.onCreateOptionsMenu(Words.java:94)
at android.support.v4.app.Fragment.performCreateOptionsMenu(Fragment.java:1582)
at android.support.v4.app.FragmentManagerImpl.dispatchCreateOptionsMenu(FragmentManager.java:1967)
at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:225)
at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:232)
at android.support.v7.app.ActionBarActivityDelegateBase.preparePanel(ActionBarActivityDelegateBase.java:617)
at android.support.v7.app.ActionBarActivityDelegateBase.supportInvalidateOptionsMenu(ActionBarActivityDelegateBase.java:421)
at android.support.v7.app.ActionBarActivity.supportInvalidateOptionsMenu(ActionBarActivity.java:172)
at com.samer.deutschwordbookapp.Words.onPrepareOptionsMenu(Words.java:117)
at android.support.v4.app.Fragment.performPrepareOptionsMenu(Fragment.java:1596)
at android.support.v4.app.FragmentManagerImpl.dispatchPrepareOptionsMenu(FragmentManager.java:1998)
at android.support.v4.app.FragmentActivity.onPreparePanel(FragmentActivity.java:481)
at android.support.v7.app.ActionBarActivity.superOnPreparePanel(ActionBarActivity.java:236)
at android.support.v7.app.ActionBarActivityDelegateBase.preparePanel(ActionBarActivityDelegateBase.java:644)
at android.support.v7.app.ActionBarActivityDelegateBase.supportInvalidateOptionsMenu(ActionBarActivityDelegateBase.java:421)
at android.support.v7.app.ActionBarActivity.supportInvalidateOptionsMenu(ActionBarActivity.java:172)
at com.samer.deutschwordbookapp.Words.onPrepareOptionsMenu(Words.java:117)
at android.support.v4.app.Fragment.performPrepareOptionsMenu(Fragment.java:1596)
at android.support.v4.app.FragmentManagerImpl.dispatchPrepareOptionsMenu(FragmentManager.java:1998)
at android.support.v4.app.FragmentActivity.onPreparePanel(FragmentActivity.java:481)
at android.support.v7.app.ActionBarActivity.superOnPreparePanel(ActionBarActivity.java:236)
at android.support.v7.app.ActionBarActivityDelegateBase.preparePanel(ActionBarActivityDelegateBase.java:644)
at android.support.v7.app.ActionBarActivityDelegateBase.supportInvalidateOptionsMenu(ActionBarActivityDelegateBase.java:421)
at android.support.v7.app.ActionBarActivity.supportInvalidateOptionsMenu(ActionBarActivity.java:172)
at com.samer.deutschwordbookapp.Words.onPrepareOptionsMenu(Words.java:117)
at android.support.v4.app.Fragment.performPrepareOptionsMenu(Fragment.java:1596)
at android.support.v4.app.FragmentManagerImpl.dispatchPrepareOptionsMenu(FragmentManager.java:1998)
at android.support.v4.app.FragmentActivity.onPreparePanel(FragmentActivity.java:481)
at android.support.v7.app.ActionBarActivity.superOnPreparePanel(ActionBarActivity.java:236)
at android.support.v7.app.ActionBarActivityDelegateBase.preparePanel(ActionBarActivityDelegateBase.java:644)
at android.support.v7.app.ActionBarActivityDelegateBase.supportInvalidateOptionsMenu(ActionBarActivityDelegateBase.java:421)
at android.support.v7.app.ActionBarActivity.supportInvalidateOptionsMenu(ActionBarActivity.java:172)
at com.samer.deutschwordbookapp.Words.onPrepareOptionsMenu(Words.java:117)
at android.support.v4.app.Fragment.performPrepareOptionsMenu(Fragment.java:1596)

空指针异常

E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at android.view.ViewConfiguration.get(ViewConfiguration.java:211)
at android.view.View.<init>(View.java:1814)
at android.view.View.<init>(View.java:1856)
at android.view.View.<init>(View.java:1834)
at android.view.ViewGroup.<init>(ViewGroup.java:285)
at android.widget.LinearLayout.<init>(LinearLayout.java:115)
at android.support.v7.widget.SearchView.<init>(SearchView.java:258)
at android.support.v7.widget.SearchView.<init>(SearchView.java:254)
at com.samer.deutschwordbookapp.Expressions$MySearchView.<init>(Expressions.java:432)
at com.samer.deutschwordbookapp.Expressions.onCreateOptionsMenu(Expressions.java:89)
at android.support.v4.app.Fragment.performCreateOptionsMenu(Fragment.java:1582)
at android.support.v4.app.FragmentManagerImpl.dispatchCreateOptionsMenu(FragmentManager.java:1956)
at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:225)
at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:232)
at android.support.v7.app.ActionBarActivityDelegateBase$1.run(ActionBarActivityDelegateBase.java:70)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

最佳答案

我最终通过变通方法解决了它,但忘记发布答案。

问题是由于 fragment 操纵导航栏以显示不同 fragment 的不同可能操作,有时,当在 fragment 之间导航时,应用程序会在上述设备上因上述错误而崩溃,在本质上这应该有效,但同样,这是一个我不完全理解的非常奇怪的 android 错误。因此,在具有导航栏的 Activity 级别上实现了一个界面,并在 fragment 中添加了界面,然后每个 fragment 仅要求 Activity 根据需要更改操作,从而防止崩溃并按预期工作

关于Android 支持库 v7 Searchview 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23045097/

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