- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
在我使用我的 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)解释为 bool 值(0x12),这是没有意义的,因为我从不处理空值或 bool 值。
日志中的资源 ID (r=0x?) 指向两种布局之一中的 View / View 属性,我将在下面介绍。
我在代码中引用这些资源 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>
光标适配器:
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源代码后,我发现“Converting to String”唯一存在的地方是在android.content.res.TypedArray
类中。
但是,我什至从未在我的项目中实例化、导入或以任何方式使用该类!这只会越来越奇怪。
编辑#3
根据评论者的要求,我已将我的 styles.xml
和 colors.xml
上传到 gist,可以在 here 找到.
最佳答案
我向 Android 团队提交了一份错误报告,因为我仍然无法解释或解决此问题。错误报告是 here .一位评论者建议我取消选中“开发人员选项”中的“启用 View 属性检查”。瞧,这个问题现在已经解决了!我不记得曾经检查过,这很奇怪,但至少我现在知道是什么导致了这个问题。
关于android - TypedValue 转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26576295/
在我使用我的 Android 应用程序时,LogCat 会随机充斥着以下 5 行的数十次重复: 10-26 12:53:30.372 21270-21270 W/Resources﹕ Convert
好的,我正在寻找过去的东西.. 每当我在我的应用中更改 Activity 时,logcat 都会报告一系列警告: 02-04 14:42:36.524: WARN/Resources(1832): C
当我们想在 Android 中改变一个 EditText 的宽度时,我们使用这行代码: int px=(int)TypedValue.applyDimension(TypedValue.COMPLEX
这是 LogCat 的摘录: 04-04 19:51:51.270: INFO/ActivityManager(57): Starting activity: Intent { cmp=com.exa
我看到以下异常: 04-06 13:35:58.498 4219 4219 E AndroidRuntime: android.view.InflateException: Binary XML
我有一个 TextView,我想为它的 textSize 设置动画。这是用于使用 ObjectAnimator 为 textSize 设置动画的代码。 val newSize = resour
跟进以下线程: Npgsql 4.0 Parameters and Null Values 对于允许强类型值的新通用参数,文档指出声明看起来像这样: cmd.Parameters.Add(new Np
这个问题在这里已经有了答案: java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILand
我正在尝试使用弹出菜单创建一个 RecyclerView,但每当我尝试访问弹出菜单时,它都会崩溃并显示: 原因:java.lang.UnsupportedOperationException:无法解析
我在实时应用程序中看到此错误,因此我不知道为什么会发生这种情况。我所拥有的只是这个异常日志(见下文)。起初,我以为我将样式 editTextBackgroungWhite(见下文)应用于我的 XML
我在对话框中有微调器,当我从微调器日志猫中选择值时显示以下消息.. 06-22 12:42:48.941: WARN/Resources(1865): Converting to string: Ty
我看到了以下异常, 只有Android SDK api level为26时才会出现,低版本没问题。 Caused by: java.lang.UnsupportedOperationException
我在 android attrs.xml 文件中添加了一个属性,用于不同的颜色深浅。在 styles.xml 文件中,我为这些属性指定了颜色,因此它们对于每种样式都是不同的。 属性.xml: 样式
当我启动我的应用程序时,出现此错误(仅在 api 22 中),显然这是我为 button_login 所做的自定义背景的一些错误 Error: android.content.res.Resource
我正在 Android Studio 上构建一个计算器应用程序。当我在 Android Pie 设备上运行该应用程序时,发生以下 fatal error 。由于我是Android开发新手,出现错误后没
将我的 Android Studio 更新到 3.0 后,我收到 No static method getFont() 错误。我正在从事的项目在 github 上,https://github.com
我是一名优秀的程序员,十分优秀!