12

我在三星 Galaxy Ace/Y/Pocket/Mini 上遇到以下崩溃。它在所有其他设备上运行良好。崩溃仅在 Android 2.3.5 或 2.3.6 上发生

堆栈跟踪中没有我的代码的引用。它似乎来自我没有自定义的菜单布局。

我怀疑这是 Galaxy OS 的故障。但无法确认。

更重要的是,我能做些什么来避免或减轻这个错误?

android.view.InflateException: Binary XML file line #45: Error inflating class 
at org.holoeverywhere.LayoutInflater._createView(SourceFile:382)
at org.holoeverywhere.LayoutInflater.onCreateView(SourceFile:594)
at org.holoeverywhere.LayoutInflater.createViewFromTag(SourceFile:444)
at org.holoeverywhere.LayoutInflater.rInflate(SourceFile:731)
at org.holoeverywhere.LayoutInflater.rInflate(SourceFile:734)
at org.holoeverywhere.LayoutInflater.inflate(SourceFile:538)
at org.holoeverywhere.LayoutInflater.inflate(SourceFile:488)
at com.android.internal.view.menu.MenuItemImpl.createItemView(MenuItemImpl.java:592)
at com.android.internal.view.menu.MenuItemImpl.getItemView(MenuItemImpl.java:577)
at com.android.internal.view.menu.MenuBuilder$MenuAdapter.getView(MenuBuilder.java:1173)
at android.widget.AbsListView.obtainView(AbsListView.java:1592)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1251)
at android.widget.ListView.onMeasure(ListView.java:1162)
at android.view.View.measure(View.java:8313)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
at android.view.View.measure(View.java:8313)
at android.view.ViewRoot.performTraversals(ViewRoot.java:845)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at org.holoeverywhere.LayoutInflater._createView(SourceFile:358)
... 26 more Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x1/d=0x7f0d014c a=3 r=0x7f0d014c}
at android.content.res.Resources.loadColorStateList(Resources.java:1804)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
at android.widget.TextView.(TextView.java:445)
at org.holoeverywhere.widget.TextView.(SourceFile:133)
at org.holoeverywhere.widget.TextView.(SourceFile:129)
... 29 more java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at org.holoeverywhere.LayoutInflater._createView(SourceFile:358)
at org.holoeverywhere.LayoutInflater.onCreateView(SourceFile:594)
at org.holoeverywhere.LayoutInflater.createViewFromTag(SourceFile:444)
at org.holoeverywhere.LayoutInflater.rInflate(SourceFile:731)
at org.holoeverywhere.LayoutInflater.rInflate(SourceFile:734)
at org.holoeverywhere.LayoutInflater.inflate(SourceFile:538)
at org.holoeverywhere.LayoutInflater.inflate(SourceFile:488)
at com.android.internal.view.menu.MenuItemImpl.createItemView(MenuItemImpl.java:592)
at com.android.internal.view.menu.MenuItemImpl.getItemView(MenuItemImpl.java:577)
at com.android.internal.view.menu.MenuBuilder$MenuAdapter.getView(MenuBuilder.java:1173)
at android.widget.AbsListView.obtainView(AbsListView.java:1592)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1251)
at android.widget.ListView.onMeasure(ListView.java:1162)
at android.view.View.measure(View.java:8313)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
at android.view.View.measure(View.java:8313)
at android.view.ViewRoot.performTraversals(ViewRoot.java:845)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method) Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x1/d=0x7f0d014c a=3 r=0x7f0d014c}
at android.content.res.Resources.loadColorStateList(Resources.java:1804)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
at android.widget.TextView.(TextView.java:445)
at org.holoeverywhere.widget.TextView.(SourceFile:133)
at org.holoeverywhere.widget.TextView.(SourceFile:129)
... 29 more android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x1/d=0x7f0d014c a=3 r=0x7f0d014c}
at android.content.res.Resources.loadColorStateList(Resources.java:1804)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
at android.widget.TextView.(TextView.java:445)
at org.holoeverywhere.widget.TextView.(SourceFile:133)
at org.holoeverywhere.widget.TextView.(SourceFile:129)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at org.holoeverywhere.LayoutInflater._createView(SourceFile:358)
at org.holoeverywhere.LayoutInflater.onCreateView(SourceFile:594)
at org.holoeverywhere.LayoutInflater.createViewFromTag(SourceFile:444)
at org.holoeverywhere.LayoutInflater.rInflate(SourceFile:731)
at org.holoeverywhere.LayoutInflater.rInflate(SourceFile:734)
at org.holoeverywhere.LayoutInflater.inflate(SourceFile:538)
at org.holoeverywhere.LayoutInflater.inflate(SourceFile:488)
at com.android.internal.view.menu.MenuItemImpl.createItemView(MenuItemImpl.java:592)
at com.android.internal.view.menu.MenuItemImpl.getItemView(MenuItemImpl.java:577)
at com.android.internal.view.menu.MenuBuilder$MenuAdapter.getView(MenuBuilder.java:1173)
at android.widget.AbsListView.obtainView(AbsListView.java:1592)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1251)
at android.widget.ListView.onMeasure(ListView.java:1162)
at android.view.View.measure(View.java:8313)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
at android.view.View.measure(View.java:8313)
at android.view.ViewRoot.performTraversals(ViewRoot.java:845)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)

这是整个theme.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="CustomWindowTitleText" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
         <item name="android:textColor">@color/primary_text_yellow</item>
         <item name="android:textStyle">bold|italic</item>
    </style>

    <style name="CustomWindowTitleText.ActionBar">
        <item name="android:textSize">@dimen/textsize_mid</item>
    </style>

    <style name="CustomWindowSubTitleText" parent="TextAppearance.Sherlock.Widget.ActionBar.Subtitle">
    </style>


    <!-- Changes the background color of the title bar -->
    <style name="CustomWindowTitleBackground">
         <item name="android:background">@drawable/background_window_title</item>
    </style>

    <!-- Set the theme for the window title -->
    <!-- NOTE: setting android:textAppearance to style defined above -->
    <style name="CustomWindowTitle">
        <item name="android:singleLine">true</item>
        <item name="android:shadowColor">#BB000000</item>
        <item name="android:shadowRadius">2.75</item>
        <item name="android:textAppearance">@style/CustomWindowTitleText</item>
        <item name="android:paddingLeft">40dp</item>
    </style>

    <!--
        http://actionbarsherlock.com/theming.html
        Due to limitations in Android's theming system any theme customizations must be declared in two attributes.
        The normal android-prefixed attributes apply the theme to the native action bar and the unprefixed attributes are for the custom implementation.
    -->
    <style name="CustomActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse"> <!--parent="@android:style/Widget.Holo.ActionBar"-->
        <item name="android:background">@drawable/gradient_lightpurple_darkpurple_off</item> <!-- Use background that has color but not icon. -->
        <item name="android:backgroundSplit">@drawable/gradient_lightpurple_darkpurple_off</item> <!-- Use background that has color but not icon. -->
        <item name="android:titleTextStyle">@style/CustomWindowTitleText.ActionBar</item>
        <item name="android:subtitleTextStyle">@style/CustomWindowSubTitleText</item>

        <item name="background">@drawable/gradient_lightpurple_darkpurple_off</item> <!-- Use background that has color but not icon. -->
        <item name="backgroundSplit">@drawable/gradient_lightpurple_darkpurple_off</item> <!-- Use background that has color but not icon. -->
        <item name="titleTextStyle">@style/CustomWindowTitleText.ActionBar</item>
        <item name="subtitleTextStyle">@style/CustomWindowSubTitleText</item>
    </style>

     <!-- Override properties in the default theme -->
     <!-- NOTE: If you change the windowTitleTextSize you must explicitly the windowTitleSize property, the title bar will not re-size automatically, text will be clipped -->
    <style name="JumbleeTheme" parent="Holo.Theme"> <!-- extends Theme.Sherlock -->
        <item name="android:windowTitleStyle">@style/CustomWindowTitle</item>
        <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
        <item name="android:windowBackground">@drawable/gradient_off_darkpurple_off</item>
        <item name="android:windowActionBar">true</item>
        <item name="android:actionBarStyle">@style/CustomActionBar</item>
        <item name="actionBarStyle">@style/CustomActionBar</item>
    </style>

    <style name="JumbleeTheme.GameScreen">
        <item name="android:windowBackground">@color/black</item>
    </style>


    <!-- Facebook Theme -->

    <style name="CustomWindowTitleText.ActionBar.Facebook">
        <item name="android:textColor">@color/primary_text_white</item>
    </style>
    <!--
        http://actionbarsherlock.com/theming.html
        Due to limitations in Android's theming system any theme customizations must be declared in two attributes.
        The normal android-prefixed attributes apply the theme to the native action bar and the unprefixed attributes are for the custom implementation.
    -->
    <style name="CustomActionBar.Facebook">
        <item name="android:background">@drawable/background_window_title_facebook</item> <!-- Use background that has color but not icon. -->
        <item name="android:backgroundSplit">@drawable/background_window_title_facebook</item> <!-- Use background that has color but not icon. -->
        <item name="android:titleTextStyle">@style/CustomWindowTitleText.ActionBar.Facebook</item>

        <item name="background">@drawable/background_window_title_facebook</item> <!-- Use background that has color but not icon. -->
        <item name="backgroundSplit">@drawable/background_window_title_facebook</item> <!-- Use background that has color but not icon. -->
        <item name="titleTextStyle">@style/CustomWindowTitleText.ActionBar.Facebook</item>
    </style>

    <!-- Facebook Sender Activity -->
    <style name="FacebookSenderTheme" parent="Holo.Theme.Light">
        <item name="android:actionBarStyle">@style/CustomActionBar.Facebook</item>
        <item name="actionBarStyle">@style/CustomActionBar.Facebook</item>
    </style>
</resources>

以及 primary_text_yellow 的来源

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:color="@color/text_light_disabled" />
    <item android:color="@color/app_yellow"/>
</selector>
4

4 回答 4

22

我很确定我也遇到过同样的问题。我敢打赌它与操作系统无关。这是由 Android 中的那件事引起的,您可以Drawable根据您的主题或其他条件将一个替换为另一个。事实证明,Android 资源编译器不会(总是?曾经?)检查别名背后是否有任何“真实”的东西。

这是你如何调试它...

从这一行开始,它会告诉你一些关于缺少什么的具体信息——ID:

Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x1/d=0x7f0d014c a=3 r=0x7f0d014c}

现在转到bin/R.text,并搜索给出的 ID 代码:0x7f0d014c。应该有这样的东西: int attr actionModeCloseDrawable 0x7f0d014c

现在在您的工作区中查找名称actionModeCloseDrawable或任何名称。相信你会发现它是一个不存在的资源的别名。即,有一个配置(版本号、屏幕大小等),在该配置下,该 attr 根本不映射到任何东西。

需要注意的重要事项:确保检查您找到的所有地方actionModeCloseDrawable或任何地方。它可能看起来像是在一个“无关紧要”的地方,但这是遇到的第二个问题:在我“修复”了一个问题之后abc_myfragment.xml,我实际上不得不修复它abc_myfragment_large.xml——Android 自动调用了一个不同的xml 文件,而不是代码中指定的文件,具体取决于我碰巧在其上运行它的设备。

堆栈跟踪的第一行应该可以帮助您验证您是否在正确的位置: android.view.InflateException: Binary XML file line #45: Error inflating class

这告诉您丢失ColorStateList的部分在某个 XML 文件的某个部分中被引用,并且那个麻烦的部分从第 45 行开始(即,打开尖括号的位置 --"<" -- 开始该部分。)

PS我所说的别名是其中之一:

<attr name="abc_my_home_button" format="reference" />

在两个单独的主题中得到单独的进一步定义:

<item name="afc_button_home">@drawable/afc_button_home_light</item>在文件themes_light.xml 中

<item name="afc_button_home">@drawable/afc_button_home_dark</item>在文件themes_dark.xml 中

当您将最终定义留在主题文件之一之外时,就会出现问题。

编辑

下一步:调查CustomActionBar的依赖关系。我不是样式方面的专家,所以我假设还有 9 个可能的位置,Android 可能会看到ColorStateList它无法找到的对 a 的引用:在CustomActionBar( Widget.Sherlock.Light.ActionBar.Solid.Inverse) 的父级中,以及它包含的 8 个项目中的每一个中. 注释掉这 8 项并摆脱父项,然后在麻烦的配置中重新运行您的应用程序。检查运行时错误是否消失,或者更有可能是更改(例如,行号(和 id)从 #45 更改以指示CustomActionBar.Facebook相反,调用了许多相同的资源)。然后一一撤消更改,直到错误变回原来的样子。这将进一步定位问题。尝试修复后,请慢慢移动,因为如果您确实发现了问题(例如,作为不存在的参考),它可能会在 8 个项目中的多个项目中重复出现。所以一一取消注释。

于 2013-09-09T07:17:16.333 回答
6

这绝对是三星 Galaxy 系列设备的几个成员中的一个错误。我设法在 Galaxy Pocket 上复制了它,但无法在模拟器上复制它以用于小型 ldpi Gingerbread 的 AVD。

重现需要一段时间。当菜单项超过 6 个时发生,因此按下硬件菜单按钮会显示 5 个项目以及“更多”溢出选项。单击“更多”会导致崩溃。

将主题修剪到以下仍然会导致错误。

<style name="CustomActionBar"> 
   <!-- No styles -->
</style>

<style name="JumbleeTheme" parent="Holo.Theme">
    <item name="android:actionBarStyle">@style/CustomActionBar</item>
    <item name="actionBarStyle">@style/CustomActionBar</item>
</style>

但是将主题缩小到以下内容会使错误消失。

<style name="CustomActionBar"> 
   <!-- No styles -->
</style>

<style name="JumbleeTheme" parent="Holo.Theme">
    <item name="actionBarStyle">@style/CustomActionBar</item>
</style>

因此,出于某种原因,Galaxy 设备正在查看“android:actionBarStyle”,即使它们不应该如此,这会使它们进入一个非常奇怪的状态。

我采用的解决方案是创建一个 values-v11 资源文件夹,其中我的 theme.xml 引用了“android:actionBarStyle”和所有其他 Honeycomb+ ActionBar 属性,并且在我的 values\theme.xml 中仅使用 ABS 属性(例如动作条样式/动作条大小)。

于 2013-09-16T10:46:37.697 回答
2

重新创建您刚刚从另一个项目复制的每个资源文件。Android 无法识别资源文件。创建新的资源文件并将旧资源文件中的代码复制并粘贴到新资源文件中。新的资源文件应该被识别并且你的颜色也会被识别

于 2015-05-14T02:13:47.990 回答
1

解决此问题的一种快速而粗略的方法是在项目文件夹中使用 grep 二进制代码。这将给出引用该值的变量的名称。例如在我的情况下是这样的 -

myviewpager/R.java:        public static final int accent=0x7f0c0000;

之后,只需将项目中该变量(重音)的所有引用替换为与项目中的某个 xml 文件相对应的硬编码值,在我的情况下是#009688。这解决了我的问题。

于 2015-06-15T20:13:25.760 回答