首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >android.view.InflateException:二进制XML文件第0行:膨胀类<unknown>时出错!

android.view.InflateException:二进制XML文件第0行:膨胀类<unknown>时出错!
EN

Stack Overflow用户
提问于 2018-06-06 18:44:16
回答 1查看 230关注 0票数 1

这是可以显示错误的方法。

错误:

由以下原因引起:

代码语言:javascript
复制
android.view.InflateException: Binary XML file line #0: Error inflating class <unknown>                                                                       

由以下原因引起:

代码语言:javascript
复制
java.lang.reflect.InvocationTargetException

下面的代码,

代码语言:javascript
复制
.inflate(R.layout.item_layout, parent, false); 

显示错误..

这是有错误的onCreateViewHolder。

代码语言:javascript
复制
    @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文件与一个错误有关。所以我发了这个。谢谢!

代码语言:javascript
复制
<?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>

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50718430

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档