unable to implement OnClickListener into seperate java class (android studio) :  OnClickListener works fine when i implement on MainActivity class of java .But its a messy practice to use on same class of main interference.
So i add a separate java class "ButtonListener.java" and wrote the following code

 

    package com.example.gowat.onclicklistner.ListenerPKG;
    import android.graphics.Color;
    import android.view.View;
    import com.example.gowat.onclicklistner.MainActivity;
    import com.example.gowat.onclicklistner.R;
 
    public class ButtonListener extends MainActivity implements View.OnClickListener {
        
                @Override
                public void onClick(View v) {
                switch(v.getId()) {
                    case R.id.button2:
                        CL.setBackgroundColor(Color.parseColor("#00ff00"));
                        break;
                    case R.id.button:
                        CL.setBackgroundColor(Color.BLUE);
                        break; }}}
and following is code of "MainActivity.java"

    package com.example.gowat.onclicklistner;
    
    import android.content.Context;
    import android.graphics.Color;
    import android.support.constraint.ConstraintLayout;
    import android.support.constraint.Constraints;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import com.example.gowat.onclicklistner.ListenerPKG.ButtonListener;
    
    public class MainActivity extends AppCompatActivity  {
       public ConstraintLayout CL;
       public Button blue,green;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            blue= (Button)findViewById(R.id.button);
            green=findViewById(R.id.button2);
            CL= findViewById(R.id.CL) ;
            ButtonListener B= new ButtonListener();
    
            blue.setOnClickListener(B);
            green.setOnClickListener(B);
    }}
     
I am trying this code but when ever i open my app and click on button it got crash.. any idea how to make it work?? i am trying it for 5 hours now :(