Apps App crashes on button click with empty edittext

I'm working on an application with some mathematical problems. I made a photo in the photoshop and under the image there is an editText and button. Everything is fine, but when I click the button when editText is empty the application crashes. I tried some solutions, but they did not help me. So if can anyone help me i would be grateful. :)

Code:
public class Start1Activity extends AppCompatActivity {

    Button btn;

    public void displayResult(String result) {
        Toast.makeText(Start1Activity.this, result, Toast.LENGTH_SHORT).show();
    }

    public void guess(View view){
        final EditText EditText2 = (EditText) findViewById(R.id.editText2);

        final int guessNumber = Integer.parseInt(EditText2.getText().toString());

        if (guessNumber == 3 ){
            displayResult("That's right! Click once again for next level");
            btn = (Button) findViewById(R.id.bt3);
            btn.setOnClickListener(new View.OnClickListener(){
                @Override
                public void onClick(View view){
                    if(EditText2.getText().toString().isEmpty()){
                        displayResult("Please enter some number");
                    }
                    Intent anythingintent=new Intent(Start1Activity.this,Start2Activity.class);
                    startActivity(anythingintent);
                }
            });
        }
        else{
            displayResult("Wrong. Try again!");

        }
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start1);
    }
}
 
D

Deleted User

Guest
I'm guessing that getText() returns null and you got a NullPointerException

Code:
if(EditText2.getText().toString().isEmpty()){

So replace the above line with

Code:
if (EditText2.getText() == null || EditText2.getText().equals("")) {
 
Top