Java 一次使用覆盖方法,一次不使用覆盖方法,两种不同的结果

Java 一次使用覆盖方法,一次不使用覆盖方法,两种不同的结果,java,Java,这个问题的答案对我很有用。但我有一个新问题。我阅读了Java语法,但我在Java语法的某些部分遇到了问题,因此,我在这里提问。我更改了代码链接的两部分,如下所示: 在Draw.java中: 我将public void onDraw(Canvas Canvas)更改为public void d(Canvas Canvas) 我在MainActivity.java中添加了以下内容 public class MainActivity extends Activity { Draw draw;

这个问题的答案对我很有用。但我有一个新问题。我阅读了Java语法,但我在Java语法的某些部分遇到了问题,因此,我在这里提问。我更改了代码链接的两部分,如下所示:

在Draw.java中: 我将
public void onDraw(Canvas Canvas)
更改为
public void d(Canvas Canvas)

我在MainActivity.java中添加了以下内容

public class MainActivity extends Activity {
    Draw draw;
    Cal cal;
    TextView textView;
    RelativeLayout linearLayout;   

    Canvas canvas;

    public void onCreate(Bundle s) {
        super.onCreate(s);
        setContentView(R.layout.activity_main);

        linearLayout = (RelativeLayout) findViewById(R.id.t);
        cal = new Cal(this);
        cal.cal();

        textView = new TextView(getApplicationContext());
        textView.setText("" + cal.result);
        textView.setTextColor(Color.RED);

        draw = new Draw(this);            

        draw.d(canvas);

        linearLayout.addView(textView);
        linearLayout.addView(draw);
    }}
public class Draw extends View {
Paint paint = new Paint();
Draw(Context context) {
    super(context);
}
public void d(Canvas canvas) {
  paint.setColor(Color.BLUE);
    canvas.drawCircle(120,120,40,paint);
    }
}
该代码可以成功编译和安装。但它只能在我的设备上运行很短时间,而且不能在AVD管理器中运行。 我确信使用的语法是正确的。但是我不知道代码冲突的原因是什么,因为我不能正确地看到输出代码

更新,Draw.java

public class MainActivity extends Activity {
    Draw draw;
    Cal cal;
    TextView textView;
    RelativeLayout linearLayout;   

    Canvas canvas;

    public void onCreate(Bundle s) {
        super.onCreate(s);
        setContentView(R.layout.activity_main);

        linearLayout = (RelativeLayout) findViewById(R.id.t);
        cal = new Cal(this);
        cal.cal();

        textView = new TextView(getApplicationContext());
        textView.setText("" + cal.result);
        textView.setTextColor(Color.RED);

        draw = new Draw(this);            

        draw.d(canvas);

        linearLayout.addView(textView);
        linearLayout.addView(draw);
    }}
public class Draw extends View {
Paint paint = new Paint();
Draw(Context context) {
    super(context);
}
public void d(Canvas canvas) {
  paint.setColor(Color.BLUE);
    canvas.drawCircle(120,120,40,paint);
    }
}

我不尝试,也许这很愚蠢,但尝试添加绘图构造函数的公共前端:

**public** Draw(Context context) {
     super(context);
}

在d()方法中,应该少一个括号。

也可以发布Draw类吗?我添加了Draw类。