Android的资源转换为字符串的TypedValue警告字符串、转换为、资源、Android

2023-09-05 23:04:29 作者:你是我遥不可及的梦

好吧,我正在寻找正确的过去的东西在这里。

Ok I'm looking right past something here..

每当我在我的应用程序,我改活动,logcat的报告一系列警告:

Every time I'm in my app and I change activities, logcat reports series of warnings:

02-04 14:42:36.524: WARN/Resources(1832): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f08002b}
02-04 14:42:36.524: WARN/Resources(1832): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f08002c}
02-04 14:42:36.524: WARN/Resources(1832): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f08002d}

其他应用程序都没有表现出这样的警告。这是一个pre释放/ AAPT COM pression事?

Other apps are not showing such warnings. Is this a pre-release/aapt compression thing?

推荐答案

您正在使用,其中一个字符串预计布尔的资源。

You are using a bool resource where a string is expected.

您可以找到它的资源正在使用错误地打开你的生成R.java文件,搜索从logcat的消息的资源ID:

You can find which resource is being used incorrectly by opening your generated R.java file and searching for the resource IDs from the logcat message:

0x7f08002b
0x7f08002c
0x7f08002d

这三个应该是从你的bool.xml文件(在警告信息的T = 0×12是指资源TYPE_INT_BOOLEAN).

然后,找到那里的资源ID被在项目中使用(可能是一个布局的XML,但可以在任何地方),并确保类型匹配。

Then, find where those resource IDs are being used in your project (probably a layout xml, but could be anywhere) and make sure the types match.

下面是一个TextView,将生成日志消息的一个例子。如果我的RES /价值/ bool.xml我有:

Here's an example of a TextView that would generate that log message. If in my res/values/bool.xml I have:

<resources>
    <bool name="foo_flag">false</bool>
</resources>

我可能会错误地引用它由AA布局xml文件:

I can incorrectly refer to it from a a layout xml file:

<TextView android:id="@+id/foo"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@bool/foo_flag"></TextView>

当我运行的应用程序,我会得到警告信息,因为文本预计字符串资源,而不是一个布尔(如预期,但因为该标志被转换成字符串false我的应用程序出现)。

When I run that app, I'll get the warning message since "text" expects a string resource, not a bool (my app appears as expected though since the flag is converted to the string "false").

 
精彩推荐
图片推荐