Question: When I do not enter anything in the EditText and then I press the "Guess" button, my app keeps crashing and I can't seem to find the problem with my code.

```
public void generateRandomNos(){
      Random rand = new Random();
      randomNumber = rand.nextInt(20)+1;
}

btnGuess.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int guessValue = Integer.parseInt(etNumber.getText().toString());
                String message;

                if(guessValue > randomNumber){
                    message = "Lower !";
                    etNumber.setText("");
                }
                else if (guessValue < randomNumber){
                    message = "Higher !";
                    etNumber.setText("");
                }
                else{
                    message = "You got it right. GG ";
                    etNumber.setText("");
                    generateRandomNos();
                }

                Toast.makeText(MainActivity.this,message,Toast.LENGTH_SHORT).show();
            }
});

```

The app should not crash when there is no text in the `EditText` box and when the button is pressed. What could be the problem?

Answer: 
As you mentioned in your question that, this error occurring when you don't enter anything in the edit text.

So first, check if the `edit text` is empty or not and then perform the required action 

```
btnGuess.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

       if(!etNumber.getText.toString().equals("")) {           
         int guessValue =  Integer.parseInt(etNumber.getText().toString());

                String message;

                if(guessValue > randomNumber){
                    message = "Lower !";
                    etNumber.setText("");
                }
                else if (guessValue < randomNumber){
                    message = "Higher !";
                    etNumber.setText("");
                }
                else{
                    message = "You got it right. GG ";
                    etNumber.setText("");
                    generateRandomNos();
                }

        Toast.makeText(MainActivity.this,message,Toast.LENGTH_SHORT).show();
            }
         } else {
           Toast.makeText(MainActivity.this,"EditText Is empty",Toast.LENGTH_SHORT).show();
         }
   });

```

> 
> **Note:** And Make sure you use `android:inputType="number"` attribute for
>  edit text so that you can get only numbers as input
> 
> 
>
Did you type any other character except decimal digit in EditText?

`parseInt` docs say: 

```
Parses the string argument as a signed decimal integer. 
The characters in the string must all be decimal digits, 
except that the first character may be an ASCII minus sign '-' ('\u002D') to 
indicate a negative value or an ASCII plus sign '+' ('\u002B') to indicate a 
positive value. The resulting integer value is returned, exactly as if the 
argument and the radix 10 were given as arguments to the 
parseInt(java.lang.String, int) method.

```

You can use the try/catch syntax for check this

```
try {
    int value = Integer.parseInt(str);
} catch(NumberFormatException ex) {
    //Input is not a number
}

```