gpt4 book ai didi

android - 不支持的操作异常 : Can't convert to color: type=0x1

转载 作者:行者123 更新时间:2023-11-30 02:20:31 26 4
gpt4 key购买 nike

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

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/custom 在我的样式 xml 文件中设置了 android:textColor。然后我只是将@color/custom 引用到android:textColor,错误消失了。

Android API 18 发生错误,API 23 运行良好。

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

关于android - 不支持的操作异常 : Can't convert to color: type=0x1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28599307/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com