【问题标题】:android.view.inflate exception, Binary xml file line #28 Error inflating class com.xyz.featureTopandroid.view.inflate 异常,Binary xml 文件行 #28 Error inflating class com.xyz.featureTop
【发布时间】:2014-11-28 11:11:30
【问题描述】:

我在将布局加载到活动时遇到错误。请看下面的代码 我的 xml 布局文件 -

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1" >

    <com.xyz.FeatureTop
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".35" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"
            android:gravity="center"
            android:text="Hello Feature Top"
            android:textColor="@android:color/black" />
    </com.xyz.FeatureTop>

    <com.xyz.Middle
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".35" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"
            android:gravity="center"
            android:text="Hello Feature Middle"
            android:textColor="@android:color/black" />
    </com.xyz.Middle>

    <com.xyz.FeatureBottom
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight=".3" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"
            android:gravity="center"
            android:text="Hello Feature Bottom"
            android:textColor="@android:color/black" />
    </com.xyz.FeatureBottom>
</LinearLayout>

下面是我的课-

public class Xyz extends TabActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    return super.onOptionsItemSelected(item);
}

public class FeatureTop extends LinearLayout implements
        IndustryCollectionDetailsListener {

    public FeatureTop(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public FeatureTop(Context context, AttributeSet attrs) {
        super(context, attrs);

    }

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

    }

    @Override
    public void featureTopDownloadSuccess() {
        // TODO Auto-generated method stub

    }

    @Override
    public void featureTopDownloadFail() {
        // TODO Auto-generated method stub

    }

    @Override
    public void featureBottomDownloadSuccess() {
        // TODO Auto-generated method stub

    }

    @Override
    public void featureBottomDownloadFail() {
        // TODO Auto-generated method stub

    }

    @Override
    public void middleDownloadSuccess() {
        // TODO Auto-generated method stub

    }

    @Override
    public void middleDownloadFail() {
        // TODO Auto-generated method stub

    }
}

public class FeatureBottom extends LinearLayout implements
        IndustryCollectionDetailsListener {

    public FeatureBottom(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public FeatureBottom(Context context, AttributeSet attrs) {
        super(context, attrs);

    }

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

    }

    @Override
    public void featureTopDownloadSuccess() {
        // TODO Auto-generated method stub

    }

    @Override
    public void featureTopDownloadFail() {
        // TODO Auto-generated method stub

    }

    @Override
    public void featureBottomDownloadSuccess() {
        // TODO Auto-generated method stub

    }

    @Override
    public void featureBottomDownloadFail() {
        // TODO Auto-generated method stub

    }

    @Override
    public void middleDownloadSuccess() {
        // TODO Auto-generated method stub

    }

    @Override
    public void middleDownloadFail() {
        // TODO Auto-generated method stub

    }

}

public class Middle extends LinearLayout implements
        IndustryCollectionDetailsListener {

    public Middle(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    public Middle(Context context, AttributeSet attrs) {
        super(context, attrs);

    }

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

    }

    @Override
    public void featureTopDownloadSuccess() {
        // TODO Auto-generated method stub

    }

    @Override
    public void featureTopDownloadFail() {
        // TODO Auto-generated method stub

    }

    @Override
    public void featureBottomDownloadSuccess() {
        // TODO Auto-generated method stub

    }

    @Override
    public void featureBottomDownloadFail() {
        // TODO Auto-generated method stub

    }

    @Override
    public void middleDownloadSuccess() {
        // TODO Auto-generated method stub

    }

    @Override
    public void middleDownloadFail() {
        // TODO Auto-generated method stub

    }

}

} 我不知道这个错误。我在xml中缺少任何属性吗?我是安卓开发新手 提前致谢。

【问题讨论】:

  • -_- 显示堆栈跟踪并显示第 28 行
  • in XML com.xyz.Xyz.Middle -> 你的包,点,类,点,内部类?
  • 堆栈跟踪 - 11-28 16:28:42.604: E/AndroidRuntime(6324): java.lang.RuntimeException: Unable to start activity ComponentInfo: android.view.InflateException: Binary XML file line # 28:膨胀类 com.xyz.FeatureTop 时出错,第 28 行是

标签: android xml android-layout android-inflate


【解决方案1】:

代替

<com.xyz.Middle
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".35" >
{...}
</com.xyz.Middle>

如果你的 Xyz 类在包 com.xyz 中,试试这个(这是内部类的语法):

<com.xyz.Xyz$Middle
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".35" >
{...}
</com.xyz.Middle>

com.xyz.FeatureBottom 等做同样的事情。

【讨论】:

  • 在加上 $ 符号后,它会删除内部类并将 xyz 作为属性。 schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight=".35" FeatureTop="" > 我得到了同样的错误。跨度>
【解决方案2】:

我观察到,如果我将班级分开,那么它的工作正常。但是,如果它的内部类它不起作用并给我那个错误。为什么会这样,我不知道。有谁知道我如何使用内部类来做到这一点?

【讨论】:

    【解决方案3】:

    我在这里找到了解决方案 - enter link description here

    我把它放在类属性中-

     <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight=".35" 
            class = "com.xyz.FeatureTop">
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@android:color/white"
                android:gravity="center"
                android:text="Hello Feature Top"
                android:textColor="@android:color/black" />
        </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 2015-01-13
      • 2016-11-03
      • 2015-08-21
      • 2012-02-09
      • 2012-03-04
      • 2013-06-25
      • 2013-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多