Simple Calculator Project (Android App)

This https://www.codecademy.com/paths/introduction-to-android-with-java/tracks/developing-an-android-application/modules/building-android-apps/informationals/simple-calculator-project

project asks to

Ensuring the app doesn’t crash when the equals button is pressed and one of the number boxes is empty.

  • When equals is pressed, before you do anything, ensure that the number boxes aren’t empty so an error doesn’t throw.

How to check whether is it something in number boxes?

Hi, and welcome to the forums :slight_smile:

If this is how you get the value from the numberBox:

numberBox.getText().toString()

…then you’d just need to check whether that equals "" (an empty String) or not.
Something like this:

if(numberBox.getText().toString() == ""){
    // do something
}else{
    // do something else
}

Hope this helped :slight_smile:

1 Like