App crashes with error "Unfortunately MyApp has stopped". How to fix?
Hi everyone. I'm a beginner in Android development in Java. I created a simple app — a calculator with two input fields and an "Add" button. When running on the emulator, everything works, but on a real phone (Android 9) when clicking the button, the app crashes with the message "Unfortunately MyApp has stopped". Here is my code in MainActivity.java:
```java
public class MainActivity extends AppCompatActivity {
EditText num1, num2;
Button addBtn;
TextView result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
num1 = findViewById(R.id.num1);
num2 = findViewById(R.id.num2);
addBtn = findViewById(R.id.addBtn);
result = findViewById(R.id.r
No answers yet.
Log in to leave an answer