Whenever I try the apk in my mobile, it crashes. I am sure it is not because of less ram or cache memory. I tries many things but they do not work. Firstly when I was adding functions to the buttons in the designing tab, then also it crashed. I searched othe forms but they did not also helped. Pls help. I have seen other forms but they dont help me at all.
package com.example.project1calculator;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
public EditText s1;
public EditText s2;
public Button sum;
public Button dif;
public Button mul;
public Button div;
public int total;
public TextView result;
public Button clear;
public String text1;
public int int1;
public String text2;
public int int2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
s1 = findViewById(R.id.editTextTextPersonName2);
s2 = findViewById(R.id.editTextTextPersonName3);
sum = findViewById(R.id.button2);
dif = findViewById(R.id.button);
mul = findViewById(R.id.button3);
div = findViewById(R.id.button4);
result = findViewById(R.id.result);
clear = findViewById(R.id.clear);
sum.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
text1 = s1.getText().toString();
int1 = Integer.parseInt(text1);
text2 = s2.getText().toString();
int2 = Integer.parseInt(text2);
total = int1 + int2;
result.setText(total);
}
});
dif.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
text1 = s1.getText().toString();
int1 = Integer.parseInt(text1);
text2 = s2.getText().toString();
int2 = Integer.parseInt(text2);
total = int1 - int2;
result.setText(total);
}
});
mul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
text1 = s1.getText().toString();
int1 = Integer.parseInt(text1);
text2 = s2.getText().toString();
int2 = Integer.parseInt(text2);
total = int1 * int2;
result.setText(total);
}
});
div.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
text1 = s1.getText().toString();
int1 = Integer.parseInt(text1);
text2 = s2.getText().toString();
int2 = Integer.parseInt(text2);
total = int1 / int2;
result.setText(total);
}
});
clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
text1 = "";
text2 = "";
int1 = 0;
int2 = 0;
}
});
}
}