app keeps stopping, but cannot find any problems



I want to debug my project, but it keeps stopping, I tried debugging it but cannot find any problems code:

TextView colorTextView;
Button plumButton;
Button blueButton;
Button goldButton;
    
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate( savedInstanceState );
    setContentView( R.layout.activity_main );
    plumButton = findViewById(R.id.plumButton);         
    plumButton.setOnClickListener( new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(v == plumButton){
                 colorTextView.setText( "Plum is a deep purple color. It is used in weedings. " );
            }
        }
    });
}

What’s wrong in my code or I is it a bug in AVD?

Answer

In onClickListener of plumButton, your are trying to set text to colorTextView, but you have not initialised at-least not in above snippet.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate( savedInstanceState );
    setContentView( R.layout.activity_main );
    plumButton = findViewById(R.id.plumButton);
    colorTextView = findViewById(R.id.colorTextView); // add this line         
    plumButton.setOnClickListener( new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(v == plumButton){
                 colorTextView.setText( "Plum is a deep purple color. It is used in weedings. " );
            }
        }
    });
}


Source: stackoverflow