简体   繁体   English

Android支持库v7 Searchview错误

[英]Android support library v7 Searchview bug

My App uses ActionBar tabs with Fragments and as a first step I used only the v4 library. 我的应用程序使用带有Fragments的ActionBar选项卡,作为第一步,我只使用了v4库。 but now I implemented the v7 appcompat as well. 但现在我也实现了v7 appcompat。 and on devices with API>11 it worked fine, Because I just use ActivityCompat.invalidateOptionsMenu(this.getActivity()); 在API> 11的设备上,它运行正常,因为我只使用ActivityCompat.invalidateOptionsMenu(this.getActivity()); but with devices with API<11 the App seemed to crash every time getActivity().supportInvalidateOptionsMenu(); 但是对于API <11的设备,应用程序似乎每次都会崩溃getActivity()。supportInvalidateOptionsMenu(); gets called saying there is an inflate exception : android.view.InflateException: Binary XML file line #85: Error inflating class and in the dalvikvm : Could not find class 'android.support.v7.widget.SearchView$5', referenced from method android.support.v7.widget.SearchView.addOnLayoutChangeListenerToDropDownAnchorSDK11 . 被调用说有一个膨胀异常: android.view.InflateException:二进制XML文件行#85:错误膨胀类和dalvikvm: 找不到类'android.support.v7.widget.SearchView $ 5',从方法引用android.support.v7.widget.SearchView.addOnLayoutChangeListenerToDropDownAnchorSDK11

I searched online for the last 3 weeks and here is stuff I managed to find: 我在网上搜索了最近3周,这里有我找到的东西:

first there is this . 首先是这个

which wasn't really enough to solve the problem but then I also found this . 这不足以解决问题,但后来我也找到了这个

Now I use eclipse but after reading Issue 67388 from the link above I downloaded android studio 0.5.4 in order to see if it will work for me as well. 现在我使用eclipse但是从上面的链接阅读了问题67388后,我下载了android studio 0.5.4以便看看它是否也适用于我。 I needed to set the Build gradle to version 0.9.0 and the android.support.v4/android.support.v7 to version 19.0.1 because with 19.1.0 the App still crashes. 我需要将Build gradle设置为0.9.0版本,将android.support.v4 / android.support.v7设置为版本19.0.1,因为使用19.1.0 App仍然会崩溃。

now the app runs okay on devices API>11 like android 2.2.3 2.3 etc but will crash if you rotate the device from NullPointerException 现在该应用程序在设备API> 11上运行正常,如Android 2.2.3 2.3等,但如果您从NullPointerException旋转设备将崩溃

the code that causes the exception according to the logcat is : 根据logcat导致异常的代码是:

mSearchView = new MySearchView(getActivity());

on 4.4 works fine, but when I run the App on android 3.0 or 4.0/4.1/4.2.1 etc the App crashes again with android.view.InflateException: Binary XML file line #85: Error inflating class and will crash when I rotate the device. 在4.4上工作正常,但当我在Android 3.0或4.0 / 4.1 / 4.2.1等上运行应用程序时,应用程序再次崩溃与android.view.InflateException:二进制XML文件行#85:错误膨胀类 ,当我旋转时会崩溃设备。

is there anyway I could solve this problem?how? 无论如何我能解决这个问题吗?怎么样? I am really stuck and don't know what to do any more Thanks in advance. 我真的被卡住了,不知道该怎么做更多先谢谢。

here is the full log cat: 这是完整的日志猫:

InflateException InflateException

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)

NullPointerException 空指针异常

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)

I ended up solving it with a workaround but forgot to post the answer. 我最终用一种解决方法来解决它,但忘了发布答案。

The problem was caused due to the fragments manipulating the nav bar to display different possible actions for the different fragments, and sometimes, when navigating between the fragments, the app would crash with the above described error on the above described devices, in essence this should work, but again, it's a really weird android bug that I didn't fully understand. 问题是由于片段操纵导航栏以显示不同片段的不同可能动作引起的,有时,当在片段之间导航时,app会因上述设备上的上述错误而崩溃,实质上这应该是工作,但同样,这是一个非常奇怪的android bug,我还没有完全理解。 So Implemented an interface on the activity level that had the nav bar and added the interface in the fragments, then each fragment simply asked the activity to change the actions based on it's needs, which prevented the crash and worked as it should 因此,在活动级别上实现了一个具有导航栏并在片段中添加了接口的接口,然后每个片段只是要求活动根据其需要更改操作,从而防止崩溃并按原样运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM