52

Ok I'm looking right past something here..

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}

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

Tobrun
  • 18,291
  • 10
  • 66
  • 81
DJC
  • 3,243
  • 3
  • 27
  • 31

6 Answers6

61

These warnings only occurred when a certain developer option was enabled.

Device Settings > Developer options > Disable 'Enable view attribute inspection'

Tobrun
  • 18,291
  • 10
  • 66
  • 81
55

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

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

All three should be from your bool.xml file (the "t=0x12" in the warning message means the resources are TYPE_INT_BOOLEAN).

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.

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>

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>

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").

Updated for Android Gradle 4.X:

As of sometime by version 4.0.1 of the Android grade plugin this has changed. An R.java file is no longer generated. Instead An R.txt file is generated located somewhere like:

    build/intermediates/runtime_symbol_list/{variant}/R.txt
David Berry
  • 40,941
  • 12
  • 84
  • 95
Mike
  • 2,422
  • 23
  • 14
  • 5
    Thanks Mike! Turned out not to be a bool resource, but checking the resource IDs was the bump I needed. I had android:text="@id/foo" - an integer @id in my TextView text field. – DJC Feb 05 '11 at 19:09
  • 2
    Interestingly, my environment (Eclipse with MOTODEV) defaults TextView text fields to have the same content as their id fields. It's nice to see the ids in the layout, but results in these warnings at runtime. No doubt there is a (minor?) performance penalty for the converts as well. – DJC Feb 05 '11 at 19:20
  • For me it wasn't the boolean stuff either but just like DJC said a text="@id/foo" somewhere. Thanks for the helping entry! – florianbaethge Sep 25 '12 at 16:10
  • Very cool, but the new version of Android Studio no longer makes R.java files! Yikes! Now what to do? – SMBiggs Mar 13 '20 at 21:04
  • @smbiggs - see my recent edit. It's now `build/intermediates/runtime_symbol_list/$variant/R.txt` – David Berry Sep 04 '20 at 03:52
3

I've discovered that this warning is also outputted when specifying a plurals string from a widget that requires parameters.

For instance:

<plurals name="song_count">
    <item quantity="one">%d song in playlist</item>
    <item quantity="other">%d songs in playlist</item>
</plurals>

The warning will appear when inflating an activity that contains a widget referencing it:

<TextView
    android:id="@+id/tv_total_songs"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@plurals/song_count" />

You no doubt replace the string after inflating the views to set the correct parameters, e.g.:

playlistSongCount.setText(
        getResources().getQuantityString(
            R.plurals.song_count,
            songCount,
            songCount));

The obvious solution here is to remove the android:text attribute from the layout as it has no purpose.

Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
2

Check to see if you don't have:-

<TextView android:text="@+id/labelText"/>

in your resource file.

Dallas Clarke
  • 261
  • 2
  • 5
0

Problem in android:text="@+id/fooText

Try change in your .xml this:

<TextView 
    android:id="@+id/foo" 
    android:text="@+id/fooText"/>

To this:

<TextView 
    android:id="@+id/foo" 
    android:text=""/>
sabadow
  • 5,095
  • 3
  • 34
  • 51
0

In my case the problem was in ListPreference default value. Even if you type it as String (for example "10") it will be interpreted as int and then converted to String and thus complaining.

For example, this will give a warning:

<ListPreference
     android:defaultValue="10"
     ...
/>

but this will not:

<ListPreference
     android:defaultValue="@string/ten"
     ...
/>

and define @string/ten in strings.xml as:

<string name="ten" translatable="false">10</string>

Dumb, but it gets rid of the warning.

lenooh
  • 10,364
  • 5
  • 58
  • 49