UnsupportedOperationException:无法转换为color:type = 0x1

时间:2015-02-19 05:37:15

标签: android android-styles

我正在使用api 21在nexus 7中运行我的应用程序。当应用程序从后台打开时 它强制关闭以下异常

java.lang.UnsupportedOperationException: Can't convert to color: type=0x1
        at android.content.res.TypedArray.getColor(TypedArray.java:404)

记录猫

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.online.Androidv2/com.online.Androidv2.PagerActivity}: java.lang.UnsupportedOperationException: Can't convert to color: type=0x1
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
        at android.app.ActivityThread.access$800(ActivityThread.java:144)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
 Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x1
        at android.content.res.TypedArray.getColor(TypedArray.java:404)
        at android.app.Activity.onApplyThemeResource(Activity.java:3674)
        at android.view.ContextThemeWrapper.initializeTheme(ContextThemeWrapper.java:140)
        at android.view.ContextThemeWrapper.setTheme(ContextThemeWrapper.java:85)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2244)
        at   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

我正在使用主题AppTheme作为应用程序。

<style name="AppTheme" parent="AppTheme.Base" />

<style name="AppTheme.Base" parent="Theme.AppCompat">
    <item name="colorPrimary">@color/theme_color</item>
    <item name="colorPrimaryDark">@color/theme_color_dark</item>
    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@android:color/white</item>
</style>

颜色值是

<color name="theme_color">#b61702</color>
<color name="theme_color_dark">#a70001</color>

我无法找到原因。有什么帮助吗?

1 个答案:

答案 0 :(得分:1)

我遇到同样的问题,在检查完代码后,我发现我使用 @ style / custom 在我的样式xml文件中设置 android:textColor 。 然后我只是将@ color / custom引用到android:textColor,错误消失了。

Android API 18中发生错误,API 23效果很好。

有用的链接:java.lang.UnsupportedOperationException: Can't convert to color: type=0x1