22

At random points while I'm using my Android application, LogCat is flooded with dozens of repetitions of the following 5 lines:

10-26 12:53:30.372  21270-21270 W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f0b00d8}
10-26 12:53:30.372  21270-21270 W/Resources﹕ Converting to string: TypedValue{t=0x1d/d=0xffe51c23 a=2 r=0x7f090047}
10-26 12:53:30.374  21270-21270 W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f0b008a}
10-26 12:53:30.375  21270-21270 W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f0b00d6}
10-26 12:53:30.375  21270-21270 W/Resources﹕ Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f0b00d7}

Using the information from the accepted answer to this question, I determined that it is trying to interpret nulls (0x0) as booleans (0x12), which makes no sense, as I'm never dealing with either nulls or booleans.

The resource IDs from the logs (r=0x?) point to views/view attributes within one of two layouts, which I'll include below.

The only places in my code where I reference those resource IDs are a) the CursorAdapter that uses the first layout, and b) a class that uses the second layout and I will include that code below as well.

I'm not sure if this is something to worry about. I know correlation does not imply causation, but when LogCat is flooded with those logs, scrolling through my app is noticeably janky.

Any help with figuring out what is going on would be appreciated.

Layout file #1:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="72dp"
    android:padding="16dp">

    <TextView
        android:id="@+id/event_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:ellipsize="end"
        android:maxLines="1"
        android:text="Title"
        android:textSize="16sp"
        android:textColor="@color/primary_text_color"/>

    <TextView
        android:id="@+id/event_dates"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@id/event_name"
        android:text="Dates"
        android:textColor="@color/secondary_text_color"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/event_location"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/event_name"
        android:layout_toLeftOf="@id/event_dates"
        android:ellipsize="end"
        android:singleLine="true"
        android:text="Location"
        android:textColor="@color/secondary_text_color"
        android:textSize="14sp" />
</RelativeLayout>

Layout file #2:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/event_type"
        android:textSize="14sp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/primary"
        android:paddingLeft="16dp"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        android:text="Header"
        android:textColor="#FFFFFF" />
</LinearLayout>

CursorAdapter:

public class EventCursorAdapter extends CursorAdapter {

    public String getKey(int position) {
        Cursor c = getCursor();
        c.moveToPosition(position);
        return c.getString(c.getColumnIndex(Database.Events.KEY));
    }

    public EventCursorAdapter(Context context, Cursor c, int flags) {
        super(context, c, flags);
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup viewGroup) {
        LayoutInflater inflater = LayoutInflater.from(context);
        return inflater.inflate(R.layout.list_item_event, viewGroup, false);
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        TextView dates = (TextView) view.findViewById(R.id.event_dates);
        Date startDate = null, endDate = null;
        Log.d(Constants.LOG_TAG, "Start: " + cursor.getString(cursor.getColumnIndex(Database.Events.START)));
        try {
            startDate = new Date(cursor.getLong(cursor.getColumnIndex(Database.Events.START)));
            endDate = new Date(cursor.getLong(cursor.getColumnIndex(Database.Events.END)));
        } catch (Exception e) {
            // Oops.
        }
        dates.setText(EventHelper.getDateString(startDate, endDate));

        TextView name = (TextView) view.findViewById(R.id.event_name);
        name.setText(cursor.getString(cursor.getColumnIndex(Database.Events.NAME)));

        TextView location = (TextView) view.findViewById(R.id.event_location);
        location.setText(cursor.getString(cursor.getColumnIndex(Database.Events.LOCATION)));
    }
}

Other class:

public class EventTypeHeader extends ListHeader {

    public EventTypeHeader(String title) {
        super(title);
    }

    @Override
    public View getView(Context c, LayoutInflater inflater, View convertView) {
        ViewHolder holder;
        if (convertView == null || !(convertView.getTag() instanceof ViewHolder)) {
            convertView = inflater.inflate(R.layout.list_item_event_type_header, null);
            holder = new ViewHolder();
            holder.text = (TextView) convertView.findViewById(R.id.event_type);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.text.setText(getText());

        return convertView;
    }

    private static class ViewHolder {
        TextView text;
    }
}

EDIT

I'll include what each resource ID references in my layout file

0x7f0b00d8: event_type

0xffe51c23: primary (my app's primary color)

0x7f0b008a: event_name

0x7f0b00d6: event_dates

0x7f0b00d7: event_location

Also, note that this is running on the 5.0 Preview. However, I still saw these logs back when I was on 4.4.4.

EDIT #2

After searching through the Android source code, I've discovered that the only place that "Converting to String" exists is in the class android.content.res.TypedArray.

However, I never even instantiate, import, or in any way use that class in my project! This just gets weirder and weirder.

EDIT #3

Per the request of a commenter, I have uploaded my styles.xml and colors.xml to a gist, which can be found here.

Community
  • 1
  • 1
Nathan Walters
  • 4,116
  • 4
  • 23
  • 37
  • 1
    +1 for teaching me janky. So the resource `r=0x7f0b00d8` for example refers to what? If you open your generated R.java file. – weston Oct 26 '14 at 18:25
  • Definitely no other references. I'd do a string search for `primary_text_color` because this line: `Converting to string: TypedValue{t=0x1d/d=0xffe51c23 a=2 r=0x7f090047}` suggests it is converting the colour (t=`0x1d`). Might be easier to track that one instance down. – weston Oct 26 '14 at 18:41
  • Also have you done a clean?, sometimes generated resources get into a funny state. – weston Oct 26 '14 at 18:42
  • Just cleaned to project; there was no change. I also searched the entire project for ```primary_text_color```, and there were only 4 references to it: its definition in ```colors.xml```, a line in ```R.java```, the above layout, and another unrelated layout. – Nathan Walters Oct 26 '14 at 18:50
  • on which device is this log from? does it happen even on emulator or nexus device? – nandeesh Oct 31 '14 at 08:49
  • I recently tested that; it occurs on my Nexus 5 running 5.0, but not my friend's identical phone. That's the really strange part. – Nathan Walters Oct 31 '14 at 11:16
  • If the same app running on phones with the same hardware and OS versions produces different outputs, one gets suspicious. My suspicion is that the print outs aren't from your app at all, but from some other app you have installed, that is not on your friends phone. Have you matched the printout PIDs with the PID of your app to ensure they really are from your app? – Enselic Nov 01 '14 at 15:08
  • I removed the package name from the log for brevity, but all the logs contain the package name of my app. – Nathan Walters Nov 01 '14 at 15:23
  • Does it happen on the emumator ? – ToYonos Nov 03 '14 at 13:43
  • Can you post your `colors.xml` and `styles.xml`? Do you have any configuration-specific implementations of these files (i.e. `values-xx` folders?) – Jeffrey Mixon Nov 05 '14 at 07:22
  • I will post those two files in a moment. I do not have any configuration-specific files that would be applicable here. EDIT I've posted the files in a gist; see the edit way at the bottom. – Nathan Walters Nov 06 '14 at 04:08
  • check this link may be it will helpful for you http://stackoverflow.com/questions/4903948/android-resources-converting-to-string –  Nov 06 '14 at 06:37
  • @Aditya believe me, I've already seen that question. It was of no help to me. – Nathan Walters Nov 06 '14 at 13:13
  • _Wild guessing now_: Does your device use `ART` instead of `Dalvik`? – Jeffrey Mixon Nov 06 '14 at 23:17
  • It's running 5.0, so yes, it does. However, like I said, I didn't see this problem on a friend's identical device. – Nathan Walters Nov 06 '14 at 23:34
  • Android L is still a preview for Nexus 5. Maybe wait a bit for the release. Do not waste too much time on this one if your app does not crash. – Vincent D. Nov 07 '14 at 00:14
  • The weird this is that my friend is running the same exact build, and he has no problems. And I could deal with a crash, but I can't deal with the massive lagging that this issue causes. If it can happen on my phone, it can happen on someone else's, no? – Nathan Walters Nov 07 '14 at 00:17
  • Maybe you can comment code little by little to see exactly the line of code that is causing those logs – mromer Nov 10 '14 at 10:04
  • I have no idea where I'd even start with that. My codebase is massive. – Nathan Walters Nov 10 '14 at 21:58

1 Answers1

29

I filed a bug report with the Android team, as I still couldn't explain or fix this issue. The bug report is here. A commenter suggested that I uncheck "Enable view attribute inspection" in the Developer Options. Lo and behold, this problem is now fixed! I don't remember ever checking that, which is weird, but at least I now know what causes this problem.

Nathan Walters
  • 4,116
  • 4
  • 23
  • 37