问题:
我的应用程序在大多数设备上运行良好,但在 HTC Desire HD (Android 2.2.1) 上崩溃。 (编辑:错误在 2.3.3 上仍然存在)
异常类 - android.content.res.Resources$NotFoundException。
源方法 - Resources.loadColorStateList()
详细信息:
我正在使用主题设置 textColor。我在布局 xml 文件中的 TextView 中声明了 textColor ...
<TextView
android:id="@+id/accountWarning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/accountWarning"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:padding="10dp"
android:textColor="?textColor"/>
并在资源主题文件中声明每个主题的 textColor 应该是什么......
<style name="Theme.TxtoolsDark" parent="Theme">
<item name="textColor">#FFFFFF</item>
<item name="autoCompleteTextViewTextColor">#000</item>
</style>
<style name="Theme.TxtoolsLight" parent="Theme" >
<item name="textColor">#000</item>
<item name="autoCompleteTextViewTextColor">#000</item>
</style>
如果我只是在我的 xml 文件中硬编码 textColor,它工作正常,所以它似乎无法理解 '?textColor' 应该让它查看我的 themes.xml 文件。同样,这在我测试过的其他设备上运行良好,但在 HTC Desire HD 上失败。
错误:
堆栈跟踪的相关位是...
android.view.InflateException: Binary XML file line #10: Error inflating class <unknown>
和
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi/scrollbar_handle_vertical.9.png from drawable resource ID #0x0: .xml extension required
at android.content.res.Resources.loadColorStateList(Resources.java:1842)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
at android.widget.TextView.<init>(TextView.java:665)
编辑: Eclipse 3.5.2 在我的 layout.xml 的图形布局选项卡中向我报告“无法解析属性“textColor”中的颜色值“?textColor”。但是,我仍然可以编译和构建,它仍然可以在除 HTC Desire HD 之外的所有其他设备上运行。完整的代码在这个问题的底部。
编辑:2011 年 7 月 1 日
我注意到我有两个独立的堆栈跟踪(尽管我认为它只有靠近末尾的 1 行有所不同)...
java.lang.RuntimeException: Unable to resume activity {uk.co.txttools.mobile.android.txttoolsmobile/uk.co.txttools.mobile.android.txttoolsmobile.pages.home.HomeTabs}: java.lang.RuntimeException: Unable to resume activity {uk.co.txttools.mobile.android.txttoolsmobile/uk.co.txttools.mobile.android.txttoolsmobile.pages.home.StandardHome}: android.view.InflateException: Binary XML file line #10: Error inflating class <unknown>
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3399)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3420)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
at android.app.ActivityThread.access$2300(ActivityThread.java:136)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2179)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:5073)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Unable to resume activity {uk.co.txttools.mobile.android.txttoolsmobile/uk.co.txttools.mobile.android.txttoolsmobile.pages.home.StandardHome}: android.view.InflateException: Binary XML file line #10: Error inflating class <unknown>
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3399)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:170)
at android.app.LocalActivityManager.dispatchResume(LocalActivityManager.java:521)
at android.app.ActivityGroup.onResume(ActivityGroup.java:58)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1260)
at android.app.Activity.performResume(Activity.java:4011)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3389)
... 12 more
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:513)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:217)
at android.app.Activity.setContentView(Activity.java:1701)
at uk.co.txttools.mobile.android.txttoolsmobile.pages.home.Home.createHomePage(Home.java:88)
at uk.co.txttools.mobile.android.txttoolsmobile.pages.home.StandardHome.createHomePage(StandardHome.java:74)
at uk.co.txttools.mobile.android.txttoolsmobile.pages.home.Home.onResume(Home.java:291)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1260)
at android.app.Activity.performResume(Activity.java:4011)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3389)
... 18 more
Caused by: java.lang.reflect.InvocationTargetException
at android.widget.TextView.<init>(TextView.java:355)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
... 33 more
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi/scrollbar_handle_vertical.9.png from drawable resource ID #0x0: .xml extension required
at android.content.res.Resources.loadColorStateList(Resources.java:1842)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
at android.widget.TextView.<init>(TextView.java:665)
... 37 more
和
java.lang.RuntimeException: Unable to resume activity {uk.co.txttools.mobile.android.txttoolsmobile/uk.co.txttools.mobile.android.txttoolsmobile.pages.home.HomeTabs}: java.lang.RuntimeException: Unable to resume activity {uk.co.txttools.mobile.android.txttoolsmobile/uk.co.txttools.mobile.android.txttoolsmobile.pages.home.StandardHome}: android.view.InflateException: Binary XML file line #10: Error inflating class <unknown>
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2485)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2506)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1856)
at android.app.ActivityThread.access$1500(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4293)
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:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Unable to resume activity {uk.co.txttools.mobile.android.txttoolsmobile/uk.co.txttools.mobile.android.txttoolsmobile.pages.home.StandardHome}: android.view.InflateException: Binary XML file line #10: Error inflating class <unknown>
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2485)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:170)
at android.app.LocalActivityManager.dispatchResume(LocalActivityManager.java:521)
at android.app.ActivityGroup.onResume(ActivityGroup.java:58)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1242)
at android.app.Activity.performResume(Activity.java:4004)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2475)
... 12 more
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:518)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:231)
at android.app.Activity.setContentView(Activity.java:1742)
at uk.co.txttools.mobile.android.txttoolsmobile.pages.home.Home.createHomePage(Home.java:88)
at uk.co.txttools.mobile.android.txttoolsmobile.pages.home.StandardHome.createHomePage(StandardHome.java:74)
at uk.co.txttools.mobile.android.txttoolsmobile.pages.home.Home.onResume(Home.java:291)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1242)
at android.app.Activity.performResume(Activity.java:4004)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2475)
... 18 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at android.view.LayoutInflater.createView(LayoutInflater.java:505)
... 33 more
Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x2/d=0x7f010001 a=-1}
at android.content.res.Resources.loadColorStateList(Resources.java:1822)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
at android.widget.TextView.<init>(TextView.java:693)
at android.widget.TextView.<init>(TextView.java:382)
... 36 more
编辑:7 月 4 日 - 完整代码
themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme" parent="android:Theme">
</style>
<style name="Theme.TxtoolsDark" parent="Theme">
<item name="textColor">#FFFFFF</item>
<item name="autoCompleteTextViewTextColor">#000</item>
</style>
<style name="Theme.TxtoolsLight" parent="Theme" >
<item name="textColor">#000</item>
<item name="autoCompleteTextViewTextColor">#000</item>
</style>
</resources>
attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="autoCompleteTextViewTextColor" format="reference|color" />
<attr name="textColor" format="reference|color" />
</resources>
myLayoutFile.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:scrollbars="vertical" android:scrollbarAlwaysDrawVerticalTrack="true">
<TextView
android:id="@+id/accountWarning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/accountWarning"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:padding="10dp"
android:textColor="?textColor"/>
<TextView
android:id="@+id/haveAccountQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/haveAccountQuestion"
android:textSize="20sp"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:textColor="?textColor"/>
<Button
android:id="@+id/yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:width="80dp"
android:text="@string/yesHappy"
android:textSize="15sp"
android:layout_gravity="center_horizontal"/>
<Button
android:id="@+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:width="80dp"
android:text="@string/noSad"
android:textSize="15sp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"/>
<ListView android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"/>
</LinearLayout>
</ScrollView>
编辑:2011 年 7 月 5 日 我发现如果我使用“android:textColorPrimary”而不是“textColor”,HTC Desire HD 上将不再出现错误,但文本颜色将始终保持不变系统文本颜色默认值。在所有设备上,它都能按预期完美运行。
编辑:2011 年 7 月 6 日清晨 基本上,HTC Desire HD 似乎会忽略任何设置为“?”的值。尽管我在上次编辑中描述了半修复,但我稍后在我的应用程序中在使用样式的页面上遇到错误。
编辑:2011 年 7 月 6 日下午晚些时候 通过在 Java 中粗略地设置文本颜色(取决于主题),我已经解决了一半的问题。但是,这还不适用于我的 ListView 中使用“样式”的文本。但是,我现在发现,尽管使用了“?textColor”,但我的程序的所有其余部分都可以正常工作!这意味着只有打开屏幕无法工作,表明 HTC Desire HD 没有足够早地创建必要的主题或样式来破译“?textColor”! (或类似的东西!)这可能是至关重要的信息!我可以交换我的代码中的任何内容以使其工作吗??
最佳答案
您在评论中提到您是在 Activity 上调用 setTheme,而不是在 list 中的 Activity 上设置主题。请确保在该 Activity 的 onCreate 生命周期方法中调用 super.onCreate 和 setContent 之前调用 setTheme。这将防止在您的主题之前使用任何默认主题。
我怀疑发生的事情是您在布局 XML 中使用“?textColor”,但此值仅在您的自定义主题和某些设备的默认主题中定义。其他设备在默认主题中没有定义的值。
错误消息是一些被放入其中的值,最终解析为无法用作文本颜色的资源。文本颜色通常是一个 XML 状态列表,指定用于某些状态的颜色,例如聚焦,但如果您希望所有状态都使用相同的颜色,有时会使用直接颜色资源。
就像我在另一条评论中提到的,我见过的大多数主题都没有直接的 textColor 值。相反,它们有一个指向样式的 textViewStyle,然后该样式具有 textColor。如果你想影响更多的东西,你可能想试试 colorForeground。通常 textViewStyle 会为 textColor 指定一个 XML 状态列表文件,然后使用 colorForeground 作为特定状态的颜色。
关于android - 仅在 HTC Desire HD 上从主题设置文本颜色失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5580290/
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我正在查看instance_variable_set的文档并看到给出的示例代码是这样做的:obj.instance_variable_set(:@instnc_var,"valuefortheinstancevariable")然后允许您在类的任何实例方法中以@instnc_var的形式访问该变量。我想知道为什么在@instnc_var之前需要一个冒号:。冒号有什么作用? 最佳答案 我的第一直觉是告诉你不要使用instance_variable_set除非你真的知道你用它做什么。它本质上是一种元编程工具或绕过实例变量可见性的黑客攻击
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我已经构建了一些serverspec代码来在多个主机上运行一组测试。问题是当任何测试失败时,测试会在当前主机停止。即使测试失败,我也希望它继续在所有主机上运行。Rakefile:namespace:specdotask:all=>hosts.map{|h|'spec:'+h.split('.')[0]}hosts.eachdo|host|begindesc"Runserverspecto#{host}"RSpec::Core::RakeTask.new(host)do|t|ENV['TARGET_HOST']=hostt.pattern="spec/cfengine3/*_spec.r
我正在玩HTML5视频并且在ERB中有以下片段:mp4视频从在我的开发环境中运行的服务器很好地流式传输到chrome。然而firefox显示带有海报图像的视频播放器,但带有一个大X。问题似乎是mongrel不确定ogv扩展的mime类型,并且只返回text/plain,如curl所示:$curl-Ihttp://0.0.0.0:3000/pr6.ogvHTTP/1.1200OKConnection:closeDate:Mon,19Apr201012:33:50GMTLast-Modified:Sun,18Apr201012:46:07GMTContent-Type:text/plain
如何使用Ruby的默认Curses库获取颜色?所以像这样:puts"\e[0m\e[30;47mtest\e[0m"效果很好。在浅灰色背景上呈现漂亮的黑色。但是这个:#!/usr/bin/envrubyrequire'curses'Curses.noecho#donotshowtypedkeysCurses.init_screenCurses.stdscr.keypad(true)#enablearrowkeys(forpageup/down)Curses.stdscr.nodelay=1Curses.clearCurses.setpos(0,0)Curses.addstr"Hello
状态:我正在构建一个应用程序,其中需要一个可供用户选择颜色的字段,该字段将包含RGB颜色代码字符串。我已经测试了一个看起来很漂亮但效果不佳的。它是“挑剔的颜色”,并托管在此存储库中:https://github.com/Astorsoft/picky-color.在这里我打开一个关于它的一些问题的问题。问题:请建议我在Rails3应用程序中使用一些颜色选择器。 最佳答案 也许页面上的列表jQueryUIDevelopment:ColorPicker为您提供开箱即用的产品。原因是jQuery现在包含在Rails3应用程序中,因此使用基