android運行時異常:Binary XML file line # : Error inflating class

自定義View時出現的,搞了好半天終於搞好了。canvas

繼承View時要要實現它全部的構造函數。ide

如:函數

 1 public class hongdian extends View {
 2     float x=40;
 3     float y=50;
 4     Paint p = new Paint();
 5    //要實現的構造
 6     public hongdian(Context context) {
 7         super(context);
 8     }
 9    //要實現的構造函數 
10     public hongdian(Context context, @Nullable AttributeSet attrs) {
11         super(context, attrs);
12     }
13     //要實現的構造函數
14     public hongdian(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
15         super(context, attrs, defStyleAttr);
16     }
17       //要實現的構造函數
18     public hongdian(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
19         super(context, attrs, defStyleAttr, defStyleRes);
20     }
21 
22     @Override
23     protected void onDraw(Canvas canvas) {
24         super.onDraw(canvas);
25         p.setColor(Color.BLACK);
26         canvas.drawCircle(x,y,15,p);
27     }
28 
29     @Override
30     public boolean onTouchEvent(MotionEvent event) {
31         x = event.getX();
32         y = event.getY();
33         this.invalidate();
34         return true;
35     }
36 }