【问题标题】:UnsupportedOperationException: Can't convert to color: type=0x1UnsupportedOperationException:无法转换为颜色:type=0x1
【发布时间】:2015-02-19 05:37:15
【问题描述】:

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

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

【问题讨论】:

  • 嗨 Sunny,你能粘贴更多的 LogCat 吗?这似乎不是您的根本原因,我在发布的 XML 中没有看到任何错误。
  • 只是一个建议,尝试将@android:color/white更改为#FFFFFF
  • @MattClark 我用 logcat 消息编辑了我的问题
  • 我会被诅咒的...嗯...this 有帮助吗?
  • 颜色,什么?它是样式属性吗?再次搜索。它可能是您正在寻找的 android:textColorandroid:background

标签: android android-styles


【解决方案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

【讨论】:

猜你喜欢
  • 2018-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多