无法启动活动 - 二进制XML文件行,错误膨胀类

时间:2014-10-01 06:39:43

标签: android inflate-exception

我完全不熟悉Android并完成我的家庭作业。我正在使用Android Studio 0.8.11。我试过搜索但没有找到合适的答案。

感谢您解密错误消息的任何帮助:

package com.mken.csd_homework5;

import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.Layout;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import org.w3c.dom.Text;


public class random_circles_activity extends Activity {
    com.mken.csd_homework5.DrawView dv;

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

DrawCircle.java

package com.mken.csd_homework5;

import android.view.View;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

public class DrawCircle extends View
{
    public DrawCircle(Context con)
    {
        super(con);
    }
}

activity_random_circles_activity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".random_circles_activity">

    <com.mken.csd_homework5.DrawCircle
        android:id="@+id/dcCustom"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button2"
        android:layout_alignBottom="@+id/button"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />
</RelativeLayout>

错误Logcat:

 10-01 02:11:35.120: E/AndroidRuntime(2910): Process: com.mken.csd_homework5, PID: 2910
 10-01 02:11:35.120: E/AndroidRuntime(2910): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mken.csd_homework5/com.mken.csd_homework5.random_circles_activity}: android.view.InflateException: Binary XML file line #18: Error inflating class com.mken.csd_homework5.DrawCircle
 10-01 02:11:35.120: E/AndroidRuntime(2910): Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class com.mken.csd_homework5.DrawCircle
 10-01 02:11:35.120: E/AndroidRuntime(2910):    at com.mken.csd_homework5.random_circles_activity.onCreate(random_circles_activity.java:22)

1 个答案:

答案 0 :(得分:2)

这可能不是答案,但我想向您展示一些代码。我想,您需要在自定义DrawCircle类中使用attributeSet设置构造函数:

        public DrawCircle(Context context)
    {
        super(context);

    }
    public DrawCircle(Context context, AttributeSet attrs)
    {
        super(context, attrs);

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

    }