我的应用程序使用带有Fragments的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但是从上面的链接阅读了问题67388后我下载了android studio 0.5.4,看看它是否也能用于我。 我需要将 Build gradle 设置为0.9.0版,将 android.support.v4 / android.support.v7 设置为版本19.0.1,因为19.1.0版本应用程序仍然崩溃。
现在应用程序在设备API&gt; 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等上运行App时,应用程序再次崩溃 android.view.InflateException:二进制XML文件行#85:错误膨胀类 旋转设备时会崩溃。
无论如何我可以解决这个问题吗?怎么样? 我真的被困住了,不知道该怎么做了 提前谢谢。
这是完整的日志猫:
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)
答案 0 :(得分:0)
我最终用一种解决方法来解决它,但忘了发布答案。
问题是由于片段操纵导航栏以显示不同片段的不同可能动作引起的,有时,当在片段之间导航时,app会因上述设备的上述错误而崩溃,本质应该可以工作,但同样,这是一个非常奇怪的android bug,我还没有完全理解。 因此,在活动级别实现了一个具有导航栏并在片段中添加了接口的接口,然后每个片段只是要求活动根据其需要更改操作,从而防止崩溃并按原样运行