Skip to content
Advertisement

Fix app keeps stopping made with android studio [closed]

I’m new in the android development field. Last night I made a simple calculator from a youtube tutorial and fortunately I’ve successfully made it. Here is the code

main.xml:-

JavaScript

mainactivity.java:-

JavaScript

But the problem is when I don’t put any value into the firstEditText or secondEditText or both of them and click on any button the app crashes and a pop up shows “myapp keeps stopping”. I want something like ” Please enter a value” shows on the blank EditText when I don’t put any value to any of EditText. Help me please

Advertisement

Answer

Your app is crashing because when you don’t enter any value and tap on buttons, it tries to parse an empty string to int which leads to a NumberFormatException and crashes your app. However, you can first check if your edit texts are empty or not before parsing them, and show a toast or a snackbar if they are empty.

Use this

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement