M
M
mixa0002021-01-06 19:46:54
android studio
mixa000, 2021-01-06 19:46:54

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

1 answer(s)
O
Oleg, 2021-01-06
@402d

5ff61a06a96fa747121093.png
You can read the error on the Run tab
, get comfortable. a more powerful logcat tool
5ff61b080a789468685540.png
If you click on the beetle instead of the green triangle, you can set breakpoints (breakpoints) in the code and then
execute it step by step

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question