LA_*_*LA_ 6 resources android android-logcat
以下是LogCat的摘录:
04-04 19:51:51.270: INFO/ActivityManager(57): Starting activity: Intent { cmp=com.example.app/.Preferences }
04-04 19:51:51.710: WARN/Resources(1081): Converting to string: TypedValue{t=0x10/d=0x0 a=-1}
04-04 19:51:51.740: WARN/Resources(1081): Converting to string: TypedValue{t=0x10/d=0x0 a=-1}
04-04 19:51:51.761: WARN/Resources(1081): Converting to string: TypedValue{t=0x10/d=0x79e a=-1}
04-04 19:51:51.800: WARN/Resources(1081): Converting to string: TypedValue{t=0x10/d=0x5a0 a=-1}
04-04 19:51:51.810: WARN/Resources(1081): Converting to string: TypedValue{t=0x10/d=0x5 a=-1}
04-04 19:51:51.830: WARN/Resources(1081): Converting to string: TypedValue{t=0x10/d=0xa a=-1}
04-04 19:51:51.840: WARN/Resources(1081): Converting to string: TypedValue{t=0x10/d=0xa a=-1}
04-04 19:51:51.860: WARN/Resources(1081): Converting to string: TypedValue{t=0x10/d=0x1e a=-1}
04-04 19:51:51.870: WARN/Resources(1081): Converting to string: TypedValue{t=0x10/d=0x1e a=-1}
04-04 19:51:53.450: INFO/ActivityManager(57): Displayed activity com.example.app/.Preferences: 2061 ms (total 2061 ms)
Run Code Online (Sandbox Code Playgroud)
big*_*nes 12
在TypedValue你从logcat的获得可以这样解释的:
t==>类型(0x10= TYPE_INT_DEC)d==>实际数据(按指定方式解释t)a==>有关价值来源的其他信息; 仅为字符串设置.r ==>最终资源ID(如果传递了文字值,则不设置)所以我猜你必须寻找你想要字符串的整数.
这个问题也困扰着我; 我发现logcat警告来自android:defaultValue,而不是<item>数组中的条目.您可以通过在xml文件中创建字符串条目来解决这些消息(我使用/xml/constants.xml,但命名约定取决于您并且无关紧要),如下所示:
<resources>
<string name="someValueA">12345</string>
<string name="someValueB">0</string>
<string name="someValueC">6789</string>
</resources>
Run Code Online (Sandbox Code Playgroud)
即使这些值是整数,因为您将它们声明为字符串,Android会将它们视为字符串,因此不会生成logcat警告.
在您的代码,引用@string/someValueA或R.string.someValueA(或B或C等)中,只要您需要放置这些值.对于ListPreferencexml文件中的a,您可以使用以下内容:
<ListPreference
android:defaultValue="@string/someValueA"
android:dialogTitle="Some dialog title"
android:entries="@array/someNamesA"
android:entryValues="@array/someValuesA"
android:key="some_preference"
android:summary="Your summary text"
android:title="Some Title" />
Run Code Online (Sandbox Code Playgroud)
一旦找到导致问题的条目,解决它并不可怕.将logcat消息中的"d"值从十六进制转换为十进制应该指向正确的方向.例如,0x5a0是1440,因此您应该能够识别代码中使用值1440的位置.
| 归档时间: |
|
| 查看次数: |
4023 次 |
| 最近记录: |