迁移到AppCompat后出现InflateException

时间:2014-08-28 13:52:08

标签: android android-appcompat

我今天在AppCompatv7的Android项目中取代了ActionBarSherlock,并迁移了所有需要的东西。现在,当ListActivity的适配器想要使xml渗透时,我得到了InflateException

    08-28 15:47:10.567: E/AndroidRuntime(32352): FATAL EXCEPTION: main
08-28 15:47:10.567: E/AndroidRuntime(32352): Process: com.sophos.smenc, PID: 32352
08-28 15:47:10.567: E/AndroidRuntime(32352): android.view.InflateException: Binary XML file line #10: Error inflating class <unknown>
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.LayoutInflater.createView(LayoutInflater.java:620)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at com.sophos.smenc.ui.adapter.SectionFileListAdapter.getView(SectionFileListAdapter.java:221)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.AbsListView.obtainView(AbsListView.java:2255)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.ListView.makeAndAddView(ListView.java:1790)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.ListView.fillDown(ListView.java:691)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.ListView.fillFromTop(ListView.java:752)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.ListView.layoutChildren(ListView.java:1630)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.AbsListView.onLayout(AbsListView.java:2087)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.View.layout(View.java:14817)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.ViewGroup.layout(ViewGroup.java:4631)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.View.layout(View.java:14817)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.ViewGroup.layout(ViewGroup.java:4631)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.View.layout(View.java:14817)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.ViewGroup.layout(ViewGroup.java:4631)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1660)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.View.layout(View.java:14817)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.ViewGroup.layout(ViewGroup.java:4631)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.View.layout(View.java:14817)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.ViewGroup.layout(ViewGroup.java:4631)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:374)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.View.layout(View.java:14817)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.ViewGroup.layout(ViewGroup.java:4631)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.View.layout(View.java:14817)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.ViewGroup.layout(ViewGroup.java:4631)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1983)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1740)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.Choreographer.doCallbacks(Choreographer.java:574)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.Choreographer.doFrame(Choreographer.java:544)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.os.Handler.handleCallback(Handler.java:733)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.os.Handler.dispatchMessage(Handler.java:95)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.os.Looper.loop(Looper.java:136)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.app.ActivityThread.main(ActivityThread.java:5001)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at java.lang.reflect.Method.invokeNative(Native Method)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at java.lang.reflect.Method.invoke(Method.java:515)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at dalvik.system.NativeStart.main(Native Method)
08-28 15:47:10.567: E/AndroidRuntime(32352): Caused by: java.lang.reflect.InvocationTargetException
08-28 15:47:10.567: E/AndroidRuntime(32352):    at java.lang.reflect.Constructor.constructNative(Native Method)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
08-28 15:47:10.567: E/AndroidRuntime(32352):    at android.view.LayoutInflater.createView(L

我没有更改适配器中的任何内容,因为我在删除时可以看到

android:background="?activatableItemBackground"

它有效。你知道这个问题是什么,我研究了几个小时,但我只能想到一个Android bug。

这是我的attrs.xml

<resources>

    <attr name="state_red" format="boolean" />
    <attr name="state_yellow" format="boolean" />
    <!--
    The ListItems reference this as background. In the styles.xml is this reference linked to an xml selector that controls 
    the color of the view according to states.
    -->
    <declare-styleable name="BaseTheme">
        <attr name="activatableItemBackground" format="reference" />
    </declare-styleable>

</resources>

1 个答案:

答案 0 :(得分:0)

和往常一样,在你要求自己得到解决方案后的短暂时间内:问题非常奇怪,在我的styles.xml中,我有以下内容:

<!-- Immediate parent theme to specify base values for custom attributes -->
<style name="Theme.Base" parent="FrameworkRoot.Theme">

    <!-- Defines the selector for the row view -->
    <item name="activatableItemBackground">@drawable/dna_list_selector_holo_light</item>
</style>

在某个地方读到名称冲突是风格的可能性后,我通过 Custom_Base_Thme 更改 Theme.Base ,现在它可以正常工作,这是我做的唯一更改。