【问题标题】:android.view.InflateException Error inflating class com.etsy.android.grid.StaggeredGridViewandroid.view.InflateException 膨胀类 com.etsy.android.grid.StaggeredGridView 时出错
【发布时间】:2014-09-08 15:51:38
【问题描述】:

我正在实现 etsy 在 github 上为 StaggeredGrid https://github.com/etsy/AndroidStaggeredGrid 提供的库。我得到的错误是布局 activity_svg.xml 的 InflationException

<com.etsy.android.grid.StaggeredGridView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:item_margin="8dp"
app:column_count="@integer/grid_column_count" />

android.view.InflationException Binary XML File Line#3 Error inflating class com.etsy.android.grid.StaggeredGridView 根据之前与问题相关的答案,我检查了构造函数:

 public StaggeredGridView(final Context context) {
    this(context, null);
}

public StaggeredGridView(final Context context, final AttributeSet attrs) {
    this(context, attrs, 0);
}

public StaggeredGridView(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);

根据之前的回答,我还检查了该文件是否位于该库中。 那么 InflationException 还有什么问题呢?为什么类没有膨胀?

如果您希望我添加更多代码部分,请发表评论。

【问题讨论】:

    标签: java android inflate-exception staggered-gridview


    【解决方案1】:

    如果您的应用程序中有自定义控件,则应使用布局 XML 中的完整包指定它,如果仅使用“yourcustomcontrol”,则会引发此错误。例如:

    <yourcustomcontrol android:id="@+id/yourCustomControl1" /> will throw error.
    <packageName.yourcustomcontrol android:id="@+id/yourCustomControl1" />
    

    会起作用。 更多自定义控件可以在android开发者主页here找到

    最初回答here

    【讨论】:

    • 我已经在代码中提到了包名。正如您在我提到的问题中看到的那样。
    猜你喜欢
    • 2020-07-28
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多