Changing the contents of the same Java Activity by pressing the button

I want to see a green rectangle first, and then when I press the button, next see a red rectangle in the same activity.I can compile the following code but the following code can not run in my device or in emulator well. I get stopped unexpectedly.Please try again

MainActivity.java

 
public class MainActivity extends Activity {
     Button button;
     Draw draw;
     Draw2 draw2;
     RelativeLayout linearLayout;
     ViewGroup.LayoutParams layoutParams;

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

    linearLayout = (RelativeLayout) findViewById(R.id.container);
    button = (Button) findViewById(R.id.button1);

    draw = new Draw(this);

    layoutParams = new ViewGroup.LayoutParams(200, 200);
    draw.setLayoutParams(layoutParams);

    linearLayout.addView(draw);

    button.setOnClickListener(new View.OnClickListener() {


        public void onClick(View v) {
            draw2 = new Draw2(getApplicationContext());
            draw2.setLayoutParams(layoutParams);
            linearLayout.addView(draw2);
        }
    });

}

}

Draw.java


public class Draw extends View {
    Paint paint;

    public Draw(Context context) {
        super(context);
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    }

@Override
    protected  void onDraw(Canvas canvas) {
    paint.setColor(Color.GREEN);
    canvas.drawRect(50,30,100,120,paint);
    super.onDraw(canvas);
    }}

Draw2.java


public class Draw2 extends View {
    Paint paint;
    Draw2(Context context){
        super(context);
      paint = new Paint();
    }
@Override
    protected void onDraw(Canvas canvas){
    paint.setColor(Color.RED);
    canvas.drawRect(50,30,100,120,paint);
super.onDraw(canvas);
}
}

Just keep learning and do not spam wrong sections