Answer the question
In order to leave comments, you need to log in
Why is the app crashing in android studio?
The application crashes when any button is pressed.
The essence of the application is that I compare the labels on the button button1 and button2 , and if they are equal, then I display Yes in the text text field, if they are not equal, then No.
The caption on button1 changes each time you click from "x" to "o" and vice versa, and the caption on button2 is always "x".
Here is the JAVA
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
boolean s = true;
Button button1, button2;
TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button) findViewById(R.id.button1);
text = (TextView) findViewById(R.id.text);
button2 = (Button) findViewById(R.id.button2);
}
public void click(View view) {
if(s) {
button1.setText("x");
s=false
}
else {
button1.setText("o");
s = true;
}
if (button1.getTag().toString().equals(button2.getTag().toString()))
text.setText("Yes");
else
text.setText("No");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question