不支持的操作异常:无法转换为颜色:类型=0x1



我正在使用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>

我找不出原因。有什么帮助吗?

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

并且在安卓API 18、API 23中出现了错误。

有用的链接:java.lang.UnsupportedOperationException:Can';t转换为颜色:type=0x1

最新更新