InflateException错误

时间:2015-07-09 15:53:18

标签: android

我是Android的初学者,在尝试编写简单游戏时遇到了问题。负责绘制所有内容的类(View)称为DrawingView。包含该视图的活动称为activity_game_board

这是整个"游戏的活动。将采取行动

var chkJobsDocketRReq = (CheckBox)this.FindControl("name_of_control");
If (chkJobsDocketRReq.Checked) {}

这是负责完成所有图纸的课程

public class GameBoard extends Activity {
    DrawingView drawView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);

        setContentView(R.layout.activity_game_board);
        TextView time_counter_tv = (TextView)findViewById(R.id.time_counter);
    }

/***/

}

这是我的activity_game_board.xml文件

public class DrawingView extends View {
    Canvas canvas;

    public DrawingView(Context context,int w, int h) {
        super(context);
         /***/
    }

    /***/

}

这是我在尝试运行应用时遇到的错误:

<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=".HomeScreen"
    android:background="@drawable/niebo">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Elapsed time: "
        android:id="@+id/time_counter"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <com.example.bouncingball2.DrawingView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/drawing_view"/>

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

您的视图需要正确的构造函数wit类android.content.Context,接口android.util.AttributeSet作为参数