这是可以显示错误的方法。
错误:
由以下原因引起:
android.view.InflateException: Binary XML file line #0: Error inflating class <unknown>
由以下原因引起:
java.lang.reflect.InvocationTargetException
下面的代码,
.inflate(R.layout.item_layout, parent, false);
显示错误..
这是有错误的onCreateViewHolder。
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int
viewType) {
if (viewType == VIEW_TYPE_ITEM)
{
View view = LayoutInflater.from(activity)
.inflate(R.layout.item_layout, parent, false);
return new ItemViewHolder(view);
}
else if ( viewType == VIEW_TYPE_LOADING){
View view = LayoutInflater.from(activity)
.inflate(R.layout.item_loading, parent, false);
return new LoadingViewHolder(view);
}
return null;
}
这是item.layout的xml代码!我认为这个xml文件与一个错误有关。所以我发了这个。谢谢!
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height= "wrap_content"
android:orientation="vertical"
app:cardElevation="10dp"
android:layout_margin="10dp"
>
<LinearLayout
android:orientation="vertical"
android:padding="10dp"
android:layout_width="match_parent"
android:background="?android:selectedWeekBackgroundColor"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txtName"
android:text="Name"
android:textSize="16sp"
android:textColor="@android:color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txtLength"
android:text="length"
android:textSize="16sp"
android:textColor="@android:color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
https://stackoverflow.com/questions/50718430
复制相似问题