TypedValue转换为String

时间:2014-10-26 18:15:36

标签: android android-resources

在我使用我的Android应用程序时随机点,LogCat充斥着以下5行的几十个重复:

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}

使用来自this question的接受答案中的信息,我确定它正在尝试将空值(0x0)解释为布尔值(0x12),这没有任何意义,因为我从未处理任何一个问题。零点或布尔值。

日志中的资源ID(r = 0x?)指向两个布局中的一个布局中的视图/视图属性,我将在下面包含这些布局。

我的代码中我引用这些资源ID的唯一地方是a)使用第一个布局的CursorAdapter,以及b)使用第二个布局的类,我也将在下面包含该代码。

我不确定这是否值得担心。我知道相关性并不意味着因果关系,但是当LogCat充斥着这些日志时,滚动浏览我的应用程序显然很笨拙。

任何有关弄清楚发生了什么的帮助都会受到赞赏。

布局文件#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>

布局文件#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)));
    }
}

其他课程:

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;
    }
}

修改

我将包含每个资源ID在我的布局文件中引用的内容

0x7f0b00d8:event_type

0xffe51c23:primary(我应用的主要颜色)

0x7f0b008a:event_name

0x7f0b00d6:event_dates

0x7f0b00d7:event_location

另请注意,这是在5.0预览版上运行的。但是,当我在4.4.4时,我仍然看到这些日志。

编辑#2

在搜索了Android源代码后,我发现了唯一一个&#34;转换为String&#34;存在于类android.content.res.TypedArray中。

但是,我甚至从未在我的项目中实例化,导入或以任何方式使用该类!这只是更奇怪和更奇怪。

编辑#3

根据评论者的要求,我已将styles.xmlcolors.xml上传到一个要点here

1 个答案:

答案 0 :(得分:29)

我向Android团队提交了一份错误报告,因为我仍无法解释或解决此问题。错误报告是here。评论者建议我取消选中“开发人员选项”中的“启用视图属性检查”。瞧,这个问题现在已经解决了!我不记得曾经检查过,这很奇怪,但至少我现在知道导致这个问题的原因了。