我正在尝试绘制一个矩形,但如果我运行它会出错。 LogFile说:无法实现类[...]没有空构造函数。但为什么呢?
public class MainActivity extends View {
public MainActivity(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Rect ourRect = new Rect();
ourRect.set(0, 0, canvas.getWidth(), canvas.getHeight()/2);
Paint blue = new Paint();
blue.setColor(Color.BLUE);
blue.setStyle(Paint.Style.FILL);
canvas.drawRect(ourRect, blue);
}
}
答案 0 :(得分:0)
您必须为您的类实现默认的空构造函数
public MainActivity() {
}