How to identify where code is incorrect, if I get warning Converting to string: TypedValue?
Asked Answered
C

3

6

Here is the extract from 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)
Chronometry answered 5/4, 2011 at 16:4 Comment(1)
Here it is pastebin.com/ZXw6ffBaChronometry
W
12

The TypedValue you get from logcat can be interpreted this way:

  • t ==> type (0x10 = TYPE_INT_DEC)
  • d ==> the actual data (to be intepreted as specified by t)
  • a ==> Additional information about where the value came from; only set for strings.
  • r ==> eventual resource id (not set if you passed a literal value)

So I guess you have to look for integers that you put where it expected strings.

Wensleydale answered 5/4, 2011 at 17:6 Comment(6)
Should I pass defaultValue in ListPreference as Integer?Chronometry
@Chronometry You could try. The funny thing is that I see in the xml (from line 107 downward) the first two 0, 0x79e, 0x5a0, 5, but one 0xa and one 0x1e, while the logcat says there are two of them.Wensleydale
Hmm. Eclipse doesn't allow me to input value like android:defaultValue=0 (as integer).Chronometry
@Chronometry : Oh, right. Another thing to notice is that actually Android knows it's an integer (t=0x10), yet it converts the value to string... hey it might depend on the type of the preference? ListPreference wants strings. See developer.android.com/reference/android/preference/…Wensleydale
@bigstones, thanks. But it is not clear for me how it should be fixed. Should I change my arrays and write items like strings? i.e. <item>"30"</item> instead of <item>30</item>?Chronometry
@LA_: I don't think you have to fix a warning. Probably the xml parser inteprets strings of digits as numbers, any fix would mean having a different string (for example if those are seconds you could put 30 sec.).Wensleydale
P
8

This issue was bothering me as well; I discovered that the logcat warnings are coming from android:defaultValue, not the <item> entries in the array. You can resolve these messages by creating string entries in an xml file (I use /xml/constants.xml, but the naming convention is up to you and does not matter) as follows:

 <resources>
      <string name="someValueA">12345</string>
      <string name="someValueB">0</string>
      <string name="someValueC">6789</string>
 </resources>

Even though those values are integers, since you are declaring them as strings, Android considers them strings so no logcat warning is generated.

In your code, reference @string/someValueA or R.string.someValueA (or B, or C, etc.) as appropriate, wherever you need to put those values. In the case of a ListPreference in an xml file, you would use something like this:

 <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" />

Once you find the entries that are causing the problem, it's not terrible to resolve it. Converting the "d" values in the logcat messages from hex to decimal should point you in the right direction. For example, 0x5a0 is 1440, so you should be able to identify where you used the value 1440 in your code.

Permanence answered 20/2, 2014 at 23:54 Comment(1)
Clean solution! I tried to assign a long int to defaultValue but failed to get the correct number. Adding the long int to resource saved me!Eroticism
R
1

I had this problem when I enabled the "Enable View Attribute Inspection" option within:

Settings > Developer Options > Debugging

Once I turned that setting off, the device stopped spamming logcat with these warnings.

Respect answered 9/2, 2016 at 8:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.